Solved objWMIService.Create need to add parameters to exe launch

Microsoft Visio professional 2003 (full...
April 16, 2014 at 15:21:37
Specs: Windows 7, Dell percision 530
I need to call an EXE remote, I need to have the server process the script.... I can get it to start the program remotely and using the remote server to do the process but i need to add parameters to the exe it is calling... these parameters will include variables defined earlier in the script.. the first paste is the code where it works

this is what works but it only starts the exe , I need to add parameters

I would like to add this line where .create is in the script

"\\"&stranswer&"\c$\temp\treesize\treesize.exe /excel strResultsLocation\tester.xls"" ""c:\temp"" /expand 5 /nogui", 0, false, null, null, intProcessID


the command line that needs to be in place is::
This is an example

treesize.exe /excel "c:\temp\test.xls" "c:\temp" /expand 1 /nogui <--- this would be the exact parametes to make this work locally in cmd

I would like to know if there is a way to plug this in with exe path and parameters for that exe to start with...
I know im probably just misplacing the quotes or something... what do i have to do so it reads the variable strresultslocation variable as expanded and not as strresultslocation

Error = objWMIService.Create()


Set fso = CreateObject("Scripting.FileSystemObject")
Do While x=o
Set sh = CreateObject("WScript.Shell")

strAnswer = InputBox("Please enter physical cluster name in which drive is hosted on:", _
"Discover resource location")

strDriveAnswer = InputBox("Please enter volume letter of a drive located on:"&" "& stranswer, _
"Discover"&" "&stranswer &"volume letter")

DestinationFile = "\\"&stranswer&"\c$\temp\treesize"
SourceFile = "c:\temp\treesize"


If strAnswer = "" Then
Wscript.quit
End if

if strDriveanswer = "" then
Wscript.quit


Else


strReultsLocation = InputBox("Please enter where on "&stranswer& " you would like to place the results file ****HINT c:\temp is a good location", _
"Location of results xls file")

wscript.echo "source"&SourceFile
wscript.echo destinationfile&"dest"
fso.Copyfolder SourceFile, Destinationfile, True

wscript.echo strAnswer&"\"&strDriveAnswer
wscript.echo "Destination"&DestinationFile


strComputer = "stranswer"
Set objWMIService = GetObject _
("winmgmts:\\" & stranswer & "\root\cimv2:Win32_Process")


Error = objWMIService.Create("\\"&stranswer&"\c$\temp\treesize\treesize.exe",null, null, intProcessID)

If Error = 0 Then
Wscript.Echo "TreeSize was started with a process ID of " _
& intProcessID & "."
Else
Wscript.Echo "TreeSize could not be started due to error " & _
Error & "."
End If
end if

loop


Learning in progress..........


See More: objWMIService.Create need to add parameters to exe launch

Report •

✔ Best Answer
April 21, 2014 at 20:10:42
Also, aren't you missing an ampersand in the following:
("\\"&stranswer&"\"strReultsLocation,null, null, intProcessID)

maybe it should be:
("\\"&stranswer&"\"&strReultsLocation,null, null, intProcessID)
If strresultslocation needs to be in quotes, maybe use chr(34) to insert them.

and for debugging, maybe make the whole string part into one string var:
creat="\\"&stranswer&"\c$\temp\treesize\treesize.exe /excel \\"&stranswer&"\"&chr(34)&strReultsLocation&chr(34)&" c:\temp /expand 1 /nogui"
wscript.echo creat
Error = objWMIService.Create(creat,null, null, intProcessID)

That way, you can view the data before it's submitted to the remote service, and the data is compiled into one discreet variable instead of patching together several.




#1
April 18, 2014 at 06:36:13
So what's stopping you?
ret = objWMIService.Create("c:\temp\treesize.exe /excel ""c:\temp\test.xls"" ""c:\temp"" /expand 1 /nogui", _
       Nothing, Nothing, intProcessID)

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

#2
April 18, 2014 at 17:45:02
it wont read the variable strReultsLocation

it reads it as literal , the user is aked to provide strReultsLocation in the input box so it can be used within
I want to use it in place in this place shown below. Sorry i dont think i showed that in my origianl post

What it does is creates my output in a folder named
strReultsLocation

("\\"&stranswer&"\"strReultsLocation,null, null, intProcessID)


strReultsLocation = InputBox("Please enter where on "&stranswer& " you would like to place the results file ****HINT c:\temp is a good location", _
"Location of results xls file")

Learning in progress..........


Report •

#3
April 18, 2014 at 19:14:55
Might try: EVAL(strReultsLocation)
This should convert the variable to its value. f/e:
leework="aaa"
worklee="bbb"
'enter one of the two above: leework or worklee
e=inputbox("enter variable name:")
wscript.echo "var name is: "&e
wscript.echo "var value of "&e&" is: "&eval(e)

Report •

Related Solutions

#4
April 21, 2014 at 07:35:23
You seem to be getting a lot of things confused here. We need to take a few steps back.

1) Where is treesize.exe, in relation to the target computer?
2) Where is the output, in relation to the target computer?
2.1) How are you going to get the results back onto your local machine?
3) Is "C:\Temp" guaranteed to exist on the remote machine?

How To Ask Questions The Smart Way


Report •

#5
April 21, 2014 at 09:48:49
1) Where is treesize.exe, in relation to the target computer? This allows us to crawl remote directories, see the size of folders... you can search folders within folders to get a count of their size , last accessed date, last written date.... Sky is the limit, but these are the parameters we are asked to use

2) Where is the output, in relation to the target computer?
treesize.exe /excel "c:\temp\test.xls" "c:\temp" /expand 1 /nogui <this is the command treesize works with when logged into suspect server with the shared drive on, I will break this command down

treesize.exe /excel "c:\temp\test.xls" <---- This tells treesize we want the output in excel <---

"c:\temp\test.xls" <---- this says where to place the output on our suspect server


"c:\temp" <---- this is telling treesize what to search, for testing purposes we want to search c:\temp

/expand 1<--- this is how many subfolder to search within our target directory (in this case c:\temp) meaning if there are folders within folder in c:\temp it will only go down one level in subfolders

/nogui <---- Since I want to run this remotely on the server behind the scenes nogui will allow .... ummmm...... NO gui lol

2.1) How are you going to get the results back onto your local machine?
I will write another script , to grab the output xls on server c:\temp><---- not a big issue this is easy

3) Is "C:\Temp" guaranteed to exist on the remote machine? <--- I have this scripted , but choose not to include it as this is not the focus right now... My focuse is being able to have .vbs read the variables in the fashion I have presented, which i know was confusing at first but with all the further explaining I have been doing hope Im starting to clear upo any and all confusion

Learning in progress..........


Report •

#6
April 21, 2014 at 11:50:12
Re: Answer to question one: Reread it. I asked where, not what.

How To Ask Questions The Smart Way


Report •

#7
April 21, 2014 at 13:16:10
Ahh got ya , I copy it to c:temp on the server
yes in our test instance c:temp exist and the copy method works...

Learning in progress..........


Report •

#8
April 21, 2014 at 13:17:37
And on the server i can see my script works . treesize.exe shows on the server in task manager as a process that was launched by my script.. It just does not accept paramaters correctly... I must be placing the quotes wrong or something to that nature....

Learning in progress..........


Report •

#9
April 21, 2014 at 20:10:42
✔ Best Answer
Also, aren't you missing an ampersand in the following:
("\\"&stranswer&"\"strReultsLocation,null, null, intProcessID)

maybe it should be:
("\\"&stranswer&"\"&strReultsLocation,null, null, intProcessID)
If strresultslocation needs to be in quotes, maybe use chr(34) to insert them.

and for debugging, maybe make the whole string part into one string var:
creat="\\"&stranswer&"\c$\temp\treesize\treesize.exe /excel \\"&stranswer&"\"&chr(34)&strReultsLocation&chr(34)&" c:\temp /expand 1 /nogui"
wscript.echo creat
Error = objWMIService.Create(creat,null, null, intProcessID)

That way, you can view the data before it's submitted to the remote service, and the data is compiled into one discreet variable instead of patching together several.



Report •

#10
April 22, 2014 at 07:14:46
nbrane: chr(34)
In VBScript, and most versions of VB, a pair of double quotes in a string produces a double quote. It's easier and less error prone than '" & Chr(34) & "'.

vande:
If the problem is with the command line, then maybe it's best to go with a different way of building it. Building an array out of your command and then joining it into a string at the end is more verbose, but it makes it easier to see / manipulate each option before you commit. This example requires .NET, as ArrayList is probably the best option for a dynamic array in VBScript. You can roll your own dynamic array, but that's beyond the scope of this post.

set cmdArgs = CreateObject("System.Collections.ArrayList")
With cmdArgs
  .Add "C:\temp\treesize\treesize.exe"
  .Add "/excel"
  .Add strReultsLocation 
  .Add """c:\temp"""
  .Add "/expand 1"
  .Add "/nogui"
End With
cmdLine = Join(cmdArgs.ToArray, " ")
WScript.Echo cmdLine

How To Ask Questions The Smart Way

message edited by Razor2.3


Report •

#11
April 22, 2014 at 07:29:25
I am very appreciative of the feedback, I will try these options tonight


thank you so kindly everyone


I wish I could mark all responses as best answer, when i finally get this working as expected... You guys are awesome <3

Learning in progress..........


Report •

Ask Question