Different Script (SAP GUI) Codes for the same process in two different computers - macros

I want to automate some operations for my works so I record a Script on SAP GUI(SAP LOGON PAD 720), then use it to create a excel macro and it works perfectly on my computer, but when I try to run it in other computers, it doesn't work at all and when I record the same process in other PC's the Script's code is different than that one which appeared in my PC. I want to know how this can be possible, how can I change the "code form" or "code language" on my PC so when I record a script it can be used on every computer.
This is the Script from my PC
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "vl03n"
session.findById("wnd[0]").sendVKey 0
'This is the script I recorded from my computer,in other pc this "LIKP-VBELN" doesnt appear
session.findById("wnd[0]/usr/ctxtLIKP-VBELN").text = "8105148724"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[7]").press
And this is if I record the same process from others PC's
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "vl03n"
session.findById("wnd[0]").sendVKey 0
'here is when the error begin "LIKP-VBELN" doesnt appear anymore so that is why the macro doesnt work
session.findById("wnd[0]/usr/ctxt").text = "8105148724"
session.findById("wnd[0]/usr/ctxt").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[7]").press

Check the LAN connection for the client and ensure its set to High Speed.
Regards,
ScriptMan

Related

How to get PlayerGUI from a Server Script?

I am working on an inventory system and and now i need to make it save, but when trying to save it prints this in the output
PlayerGui is not a valid member of Player "Players.RidhoMBLR"
local function save(player)
local invTable = {}
for i, v in pairs(player.PlayerGui.ScreenGui.Inventory.InvFrame:GetChildren()) do
if v:IsA("TextButton") then
table.insert(invTable, v)
end
end
dataStore:SetAsync(player.UserId, invTable)
end
players.PlayerRemoving:Connect(save)
While you are accessing the path to the PlayerGui correctly, it is probably not replicated to the server (ie, it's existence is only observable on the client in LocalScripts).
So you will likely need to use a LocalScript to pull all of the relevant information out of the UI, and communicate it up to the server using a RemoteEvent. So move your code to a LocalScript :
local players = game.Players
local saveEvent = game.ReplicatedStorage.RemoteEvent -- find your RemoteEvent here
local function save(player)
-- only tell the server about it if we are the one leaving
if player ~= players.LocalPlayer then
return
end
-- get information about the inventory
local inventory = player.PlayerGui.ScreenGui.Inventory.InvFrame:GetChildren()
local invTable = {}
for i, v in ipairs(intentory) do
if v:IsA("TextButton") then
-- grab the text out of each button
table.insert(invTable, v.Text)
end
end
-- tell the server about our inventory
saveEvent:FireServer(invTable)
end
players.PlayerRemoving:Connect(save)
Then in a server Script, listen for when clients fire the event and save their data then :
local saveEvent = game.ReplicatedStorage.RemoteEvent -- find that same RemoteEvent
-- listen for when players report that they are leaving
saveEvent.OnServerEvent:Connect(function(player, inventoryTable)
-- save their information
dataStore:SetAsync(player.UserId, inventoryTable)
end)
So basically you can't access a player's PlayerGui through the server. PlayerGui is replicated locally for each client, hence in order to interact with a Player's Gui I'd recommend using RemoteEvents. By using Remote events you'd be sending a signal to the client which can then by picked up by a LocalScript. On the local script you can then fire another RemoteEvent back to the server with a list of all the items which you can then SetAsync on the server.

how to query userinput via phone, within matlab

Conceptual question:
How can I query userinput via phone (android) within a matlab script running on a server? What would it take to make this work? Could this be achieved using a COM interface like outlook's?
Thanks
Here's the code I wrote to make this happen, suggestions welcome...
install matlab app then...
%matlab instance #1, run on server
t = tcpip('0.0.0.0', 1234, 'NetworkRole', 'server');
fprintf('server is set up. \n\nwaiting for client to connect... ');
fopen(t);
fprintf('connected.\n')
fprintf('listening for user commands...\n\n');
while true
if t.BytesAvailable>0
data = fread(t,t.BytesAvailable);
if data==1
disp('1')
elseif size(data,1)>1 %parse several integers as strings
switch char(data')
case 'asdf'
disp('do asdf');
% >> at this point any input can be run using 'eval' << %
end
end
else
pause(2); %wait some seconds
end
end
%matlab instance #2, run on same server
%enable mobile app connection
connector on;
(connect then via mobile app, run following code from the mobile console)
try
t = tcpip('localhost',1234);
fclose(t)
fopen(t)
catch
fprintf('connection failed.\n');
return
end
fprintf('connection established.\n')
% send command to server
fwrite(t,'asdf')

How to setup email notification alert in IIS 6.0 web server when a file is uploaded via any ftp client?

I'm trying to setup email notification alerts in IIS 6 when a file is uploaded via any FTP client. Does anyone know how to accomplish this?
I found something similar but don't understand how to implement it:
http://forums.iis.net/t/1196793.aspx/1?How+to+add+email+notification+service+in+IIS+6+0+when+a+file+is+uploaded+via+FTP+
Does anyone have any insight on this?
function countFolders(strPath)
dim objShell
dim objFolder
dim folderCount
set objShell = CreateObject("shell.application")
set objFolder = objShell.NameSpace(strPath)
if (not objFolder is nothing) then
dim objFolderItems
set objFolderItems = objFolder.Items
if (not objFolderItems Is Nothing) then
folderCount=objFolderItems.Count
end if
set objFolderItem = nothing
end if
set objFolder = nothing
set objShell = nothing
countFolders=folderCount
end function
The post you're citing basically suggests this:
Create a script which checks the number of files in a folder(or folders) (as you have).
Create a running total of number of files. Maybe save this value into a database or another txt file.
If the number of files differs from the last time the check was ran, then send the email.
It suggests using scheduled tasks. This means an email is sent exactly when the FTP is updated only when you script is executed. The good thing about Windows Tasks is you can run it as often as you like. So, assuming you don't need an immediate notification, you could set your script to run once a minute, once every 10 minutes or similar.
The problem with the above though is if people are removing files as well, you'll probably get missed notifications. EG assuming you don't want to be notified when a file is removed, this means if my current count of files is 10, 3 and removed and 1 added, this means next time the script runs I have 8 files. There is no way to know that files had been removed/re-added. In this case, you want to take a notice of the file-names and paths, make a note of them so you can compare existing paths to previous paths!
I have just completed a very similar task, but I had an extra luxury. I wrote the FTP client which had to be installed on all clients machines to send files to my FTP. This meant, in my FTP program, I had an extra bit of code which did: OnUploadCompleted -> Send Notofication Email
You could create a service which uses the FileSystemWatcher.
The FileSystemWatcher listens to files system change notifications. In the provided link is a good example how to use the class.

Run URL in Background as Service

I'm looking for a way to create a file that runs a specific URL in the background at a specific time. I'll run the service on a timer, and the user won't be logged in. Basically, the server restarts every day, and I want to run a service at 6AM that just goes to a URL (which will automatically complete some tasks). I was thinking batch file or even AHK..but is there a simple way to do this?
My comment:
You just want to open a URL that itself start some tasks? Tried iexplore.exe "your url" as a windows task?
Add:
If this don't work you can just write a small script in vbscript which you fire as task sheduler task.
This script just opens your url:
Dim l_lTimeoutResolve, l_lTimeoutConnect, l_lTimeoutSend, l_lTimeoutReceive, l_sUrl
l_lTimeoutResolve = 5000
l_lTimeoutConnect = 60000
l_lTimeoutSend = 10000
l_lTimeoutReceive = 10000
l_sUrl = "http://yoururl"
'Dim l_sRequestText : l_sRequestText = "stuff you want to send"
Dim l_oXML : Set l_oXML = CreateObject("MSXML2.ServerXMLHTTP")
l_oXML.setTimeouts l_lTimeoutResolve, l_lTimeoutConnect, l_lTimeoutSend, l_lTimeoutReceive
l_oXML.open "POST", l_sUrl, False
l_oXML.setRequestHeader "Content-Type", "text/xml"
' you can post data and als get a result then to write to a logfile e.g.
'l_oXML.send l_sRequestText
'l_sResponseText = l_oXML.responseText
Pro's prolly post that you better do this as powershell .NET script instead, but I never get used to that now. If you want todo coding in .NET instead (vbscript is a bit tricky to setup security on windows 2008 servers) then better write a simple .exe file in .NET that you just start.
Wrap it in a batch file and create a Windows scheduled tasks to execute it?
edit: massive assumption that you are running in windows... but you get the gist

Controlling a matlab script (Pause, Reset)

I am trying to create a matlab script (m-file) which shall be controlled by an external VBA script.
The matlab script shall do the same operation every time (even params change, but this is not the matter in this case) for a certain number of loops.
If I see it right, I can use matlab funktions in VBA like this: http://www.mathworks.de/help/techdoc/matlab_external/f135590.html#f133975
My main problem is how to implement the matlab part of this problem...at the moment my control part looks like this:
start.m:
run = 1;
reset = 0;
while run ~= 0 % Loop until external reset of 'run' to '0'
if reset ~= 0
doReset(); % Reset the parameters for the processing
reset = 0;
disp('I did a reset');
end
disp('I am processing');
doProcess();
pause(1)
end
disp('I am done');
The reset part works very fine while changing the value by the script, but when I manually try to change the value of 'run' or 'reset' to any other value in my workspace, nothing happens...my script doen't abort, neither does the reset-if do it's work...
this seems to me that the script doesn't recognize any changes in the workspace?!
later the variables 'run' and 'reset' shall be set or unset by the VBA script.
Is there any plausible reason why I can't abort the loop by hand?
Thanks for any advice!
greets, poeschlorn
Edit:
It seems that the script loads the variables once before starting and never again during runtime...is there a possibility to have explicit access to a workspace variable?
Edit 2:
I use Matlab 2010b with no additional Toolboxes at the moment
Edit 3:
I found out, that there are several 'workspaces' or RAMs in Matlab. If my function is running, the variables are stored in 'base' (?) workspace, which is not the matlab workspace on which you can click and change every value. So I have to get access to this ominous 'base' space and change the flag 'run' to zero.
I assume your problem is simply that your loop is blocking execution of the external interface. While the loop runs you cannot access the other interfaces.
I wanted to do a similar thing -- allow control of a matlab loop by an external program (either Ruby or another matlab instance). The most flexible solution by far was using UDP. There is a great toolbox called PNET for matlab, and I assume VB must have a socket library too. I simply open a UDP port on both sides, and use simple text commands to control and give feedback.
obj.conn = pnet('udpsocket', 9999);
command = '';
while run ~= 0
nBytes = pnet(obj.conn, 'readpacket');
if nBytes > 0
command = pnet(obj.conn, 'read', nBytes, 'string');
end
switch command
case '--reset--'
doReset(); % Reset the parameters for the processing
reset = 0;
disp('I did a reset');
case '--abort--'
run = 0;
disp('Going to abort');
case '--echo--'
pnet(obj.conn, 'write', '--echo--');
pnet(obj.conn, 'writepacket', remoteAddress, remotePort);
end
doProcess();
end
This way I can build my own extensible control interface without worrying about blocking from the loop, it can work cross-platform and cross-language, can work within a machine or across the network.
UPDATE:
To talk between two UDP clients, you need to set up two complimentary UDP ports, both are clients (this example is all in matlab, pretend obj here is a structure, in my case it is a class i wrap around the pnet functionality):
obj = struct();
obj.success = 0;
obj.client1Port = 9999;
obj.client2Port = 9998;
obj.client1Address = '127.0.0.1';
obj.client2Address = '127.0.0.1';
obj.conn1 = pnet('udpsocket', obj.client1Port);
obj.conn2 = pnet('udpsocket', obj.client2Port);
pnet(obj.conn1, 'write', '--echo--')
pnet(obj.conn1, 'writepacket', obj.client2Address, obj.client2Port);
nBytes = pnet(obj.conn2, 'readpacket');
if nBytes > 0
command = pnet(obj.conn2, 'read', nBytes, 'string');
if regexpi(command,'--echo--')
obj.success = obj.success+1;
fprintf('Client 2 recieved this message: %s\n',command);
pnet(obj.conn2, 'write', '--echo--')
pnet(obj.conn2, 'writepacket', obj.client1Address, obj.client1Port);
end
end
nBytes = pnet(obj.conn1, 'readpacket');
if nBytes > 0
command = pnet(obj.conn1, 'read', nBytes, 'string');
if regexpi(command,'--echo--')
obj.success = obj.success+1;
fprintf('Client 1 got this back: %s\n',command);
end
end
if obj.success == 2
fprintf('\nWe both sent and received messages!\n');
end
Is your script a script m-file or a function?
If it's a function, you'll be losing the scope of the workspace variables which is why it's not working. I'd turn your code into a function like this:
function processRun(run,reset)
while run ~= 0 % Loop until external reset of 'run' to '0'
if reset ~= 0
doReset; % Reset the parameters for the processing
reset = 0;
disp('I did a reset');
end
disp('I am processing');
[run,reset] = doProcess;
pause(1)
end
You can then set the values of run and reset evertime you call the function from VBA.
If you have a script, try removing the run and reset lines from the top, and set their values in the workspace before you run the script. I think you're overwriting your workspace values by running the script file.
Sorry, I don't have enough rep to make a comment so I'll quote it here:
#Adam Leadbetter: Thanks, this makes sense. The only thing I habe trouble with is how to pause (after this reset and then resume) the script when it has been started by run=1 as param... – poeschlorn Feb 25 at 7:17
If you want to break out of the loop once reset has been set to one, and then wait for the loop to continue again once run = 1 that is pretty much the same as just starting over again?
function processRun()
run = 1;
while run ~= 1
run = doProcess();
end
if doProcess() returns 0 then the function processRun() will end (like the behaviour you want to have when reset), the next time processRun is called it starts over, with "reset"/default values.
Or am I missing something?