The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Run a command line Internal to SLX?
Posted: 01 May 07 3:10 PM
|
fiogf49gjkf0d Hi all;
I am trying to delete a file on an external machine from a specific user event inside of SLX. The files exist on an external Server that is not in the same domain as SLX. It is, however, running the SLXOLEDB provider - sending and receiving data to an outward facing web site.
One of the things I am looking at is the sysinternals tool of psexec. This tool works like a dream, when I have the ability to run it from command line. I feed it psexec, a small batch file, and a file variable.
Does anyone know how to run a command line from inside of SLX?
Example: psexec \\myOtherServer -c c:\Myfolder\MyBatch.File c:\myVariableToNameThePathAndFile.file
eek! or is that Geek?
Carla |
|
|
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 3:22 PM
|
fiogf49gjkf0d Carla, try this:
psexec \\myOtherServer -u DOMAIN\username -p password -c c:\Myfolder\MyBatch.File c:\myVariableToNameThePathAndFile.file |
|
|
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 3:31 PM
|
fiogf49gjkf0d Hi David.
Thanks for the quick reply! I'm not having problems using the psexec. I just don't know how to call this run command from SLX. Suggestions?
i.e. In SLX Active Form; from a button click
////////////////////////////////
Sub cmdMyAction_OnClick()
'gather information here to create my path and file
'run the command line .... with my params
End Sub
|
|
|
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 3:49 PM
|
fiogf49gjkf0d Hi Carla,
You can use the Shell object in a script to execute it by way of command.com. Something along these lines:
Dim shell Dim cmdline cmdline = "psexec \\myOtherServer -c c:\Myfolder\MyBatch.File c:\myVariableToNameThePathAndFile.file" Set shell = CreateObject("WScript.Shell") shell.Run "command.com /k " & cmdline Set shell = Nothing
This may or may not work, but worth a try. Otherwise, you could always just write out the entire command-line string to a text file, name it whatever.bat and then run that. Know what I mean?
-Ryan |
|
|
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 3:51 PM
|
fiogf49gjkf0d Thanks Ryan,
I'll give this a shot.
I think I know what you mean by the other. Create a fso object (create, write, close a text file) then execute it?
c |
|
|
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 3:51 PM
|
fiogf49gjkf0d BTW, you can also try enclosing the entire command line string in quotes - ie: Chr(34) & "my command line" & Chr(34). Also, I can't remember for sure if the param to command.com needs to be "k" or "c" to execute the command. |
|
|
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 3:53 PM
|
fiogf49gjkf0d Originally posted by Carla Tillman
Thanks Ryan,
I'll give this a shot.
I think I know what you mean by the other. Create a fso object (create, write, close a text file) then execute it?
c |
|
Right. |
|
|
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 3:55 PM
|
fiogf49gjkf0d One more thing, I think you can also use the environment var COMSPEC for this:
Dim shell Set shell = CreateObject("WScript.Shell") shell.Run = "%COMSPEC% " & cmdline Set shell = Nothing
The COMSPEC var might use a newer construct than command.com, but I don't really remember for sure. |
|
|
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 4:54 PM
|
fiogf49gjkf0d Ryan,
Quick follow up:
%COMSPEC% I tried this from an Active form and received the following error.
--------------------------- Script Error --------------------------- ... ...
Object doesn't support this property or method: 'shell.Run' ...
************************
However, it does appear the command.com version will work if I can get everything in the right place.
Carla |
|
|
| |
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 5:02 PM
|
fiogf49gjkf0d I'm Fairly certain that moving my psexec and batch file to the SalesLogix folder or pathing it is all that is required at this point.
Sub DeleteLicKeyFile()
Dim shell Dim cmdline Dim PathAndFile
cmdline = "psexec \\MyServer -c c:\PStools\Delete.cmd " & "c:\testfolder\test.txt" msgbox cmdline
Set shell = CreateObject("WScript.Shell") Shell.Run "command.com /k " & cmdline Set shell = Nothing
'This version returned the error
' Set shell = CreateObject("WScript.Shell") ' shell.Run = "%COMSPEC% " & cmdline ' Set shell = Nothing
End Sub
|
|
|
| |
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 5:27 PM
|
fiogf49gjkf0d Change to this and you should be good to go (notice the "/C", I forgot that in my sample I posted earlier)
Sub DeleteLicKeyFile() Dim shell Dim cmdline cmdline = "psexec \\MyServer -c c:\PStools\Delete.cmd " & "c:\testfolder\test.txt" Set shell = CreateObject("WScript.Shell") shell.Run = "%COMSPEC% /C " & cmdline Set shell = Nothing End Sub |
|
|
|
Re: Run a command line Internal to SLX?
Posted: 01 May 07 6:03 PM
|
fiogf49gjkf0d Still couldn't get that to go. I would have to poke around and see how my environment variables have been set.
However, I did finally get the syntax down on the other method. *WHEW* Rather than move my psexec and dangerous delete file to the SalesLogix folder, I wanted to keep it somewhat separate so I can apply at least a modicum of security.
Set shell = CreateObject("WScript.Shell") Shell.Run "command.com /c" & "C:\PSTOOLS\" & cmdline Set shell = Nothing
Thank you for all of your help Ryan. I was lost on this one!
 Carla
|
|
|
|
Re: Run a command line Internal to SLX?
Posted: 02 May 07 3:10 PM
|
fiogf49gjkf0d I know this is old but bear with me. Command.com is a Windows 98'ish thing. Windows NT (2000, XP, the only OS SalesLogix now supports) uses cmd.exe I believe. I think command.com is a simple pass-through to cmd.exe on those systems but you'll likely find a time soon where it may no longer be included. |
|
|
|
Re: Run a command line Internal to SLX?
Posted: 02 May 07 3:59 PM
|
fiogf49gjkf0d That is true. I believe the %COMSPEC% env var maps to the most current command interpreter, which would be cmd.exe for any systems SLX runs on. The code could also use cmd.exe directly as well (which would be better than using command.com directly also).
Thanks for pointing that out. |
|
|
| |
|