Sign in to follow this  
Followers 0
Falcor

objShell.Run issues...

45 posts in this topic

Hey guys/gals! At work, I do a lot of EDI processing. In order to cut down on the time it takes to locate each Excel spreadsheet, application, virtual machine, etc. I need to access while processing EDI, I have created an HTA utility that pretty much does everything I need: For each type of client EDI being processed, it executes specific applications, websites, yatta yatta.

Here's the rub: I have incorporated a check for the "Program Files (x86)" folder (a kind of 64-bit OS check). Since I have done this, I cannot get VMWare Infrastructure Client to run! When I create a test snippet with the same code and remove the objShell.Run command and replace it with a simple message box telling me what variables it has stored, everything is accurate. So, I simply cannot figure out how this is wrong...

Program Files check:

Set objShell = CreateObject("WScript.Shell")
ProgFilesPath = objShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")

This works wonderfully - on 64-bit machines, it returns

C:\Program Files (x86)

On 32-bit machines, it returns

C:\Program Files

However, when I try to pass any of the following, I get a Path not found error...

objShell.run ProgFilesPath & "\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe -s 192.168.1.201 -u root -p " & RootPassword.Value,1,False

PathTIE = chr(34) & objShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%") & "\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe -s 192.168.1.204 -u root -p " & RootPassword.Value & chr(34)
objShell.run PathTIE,1,False

I have tried different permutations of quotes, both with and without and I simply can't get it to work! Can someone tell me what I am doing wrong?

Thanks, in advance, for your help!

0

Share this post


Link to post
Share on other sites
Set objShell = CreateObject("WScript.Shell")  
ProgFilesPath = objShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")
If Not objFSO.FolderExists(ProgFilesPath) Then
ProgFilesPath = objShell.ExpandEnvironmentStrings("%ProgramFiles%")

objShell.Run(Chr(34)ProgFilesPath & "\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" & " -s 192.168.1.201 -u root -p " & RootPassword.Value & Chr(34), 1, False)

0

Share this post


Link to post
Share on other sites

Set objShell = CreateObject("WScript.Shell")  
ProgFilesPath = objShell.ExpandEnvironmentStrings("%ProgramFiles(x86)%")
If Not objFSO.FolderExists(ProgFilesPath) Then
ProgFilesPath = objShell.ExpandEnvironmentStrings("%ProgramFiles%")

objShell.Run(Chr(34)ProgFilesPath & "\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" & " -s 192.168.1.201 -u root -p " & RootPassword.Value & Chr(34), 1, False)

Sorry, I should have mentioned that this will be running as part of a sub. Thus, I cannot use parentheses.

0

Share this post


Link to post
Share on other sites

This seems to be a problem read this Thread

This doesn't seem to apply. I can run Msgbox commands out the whazzoo and it will return the correct path every single time, regardless of being run on a 32/64-bit machine.

Here is another test I ran where I hard coded the direct path to the executable:

Dim objFileSys, OSBit, objShell, PathTIE, PathTLW

Set objFileSys = CreateObject("Scripting.FileSystemObject")
If (objFileSys.FolderExists("C:\Program Files (x86)")) Then
OSBit = "64"
Else
OSBit = "32"
End If

If OSBit = "64" Then
Set objShell = CreateObject("WScript.Shell")
PathTIE = chr(34) & "C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe -s 192.168.1.204 -u root" & chr(34)
PathTLW = chr(34) & "C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe -s 192.168.1.201 -u root" & chr(34)
objShell.run PathTIE,1,False
objShell.run PathTLW,1,False
ElseIf OSBit = "32" Then
Set objShell = CreateObject("WScript.Shell")
PathTIE = chr(34) & "C:\Program Files\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe -s 192.168.1.204 -u root" & chr(34)
PathTLW = chr(34) & "C:\Program Files\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe -s 192.168.1.201 -u root" & chr(34)
objShell.run chr(34) & PathTIE & chr(34),1,False
objShell.run chr(34) & PathTLW & chr(34),1,False
Else
Msgbox "Error! No OS bit-level detected."
End If

This is simply strict VBScript...there is no HTA involved here...and it STILL says "Cannot find the file specified". Again, with the code above, I have tried just about every permutation of chr(34), """, "", ", etc. to try to see what the heck the issue is.

Thanks again for your replies.

0

Share this post


Link to post
Share on other sites

Hey guys. Looks like I solved my own problem. It appears as though the arguments I was passing with the run command have to be in a separate entity (Really MS??).

Here is the code I tested - It works without fail:

Dim objFileSys, OSBit, objShell, PathTIE, PathTLW, TIEArgs, TLWArgs

TIEArgs = " -s 192.168.1.204 -u root"
TLWArgs = " -s 192.168.1.201 -u root"

Set objFileSys = CreateObject("Scripting.FileSystemObject")
If (objFileSys.FolderExists("C:\Program Files (x86)")) Then
OSBit = "64"
Else
OSBit = "32"
End If

If OSBit = "64" Then
Set objShell = CreateObject("WScript.Shell")
PathTIE = chr(34) & "C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" & chr(34)
If (objFileSys.FileExists(PathTIE)) Then
Msgbox PathTIE & TIEArgs
Else
Msgbox PathTIE
End If
PathTLW = chr(34) & "C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" & chr(34)
If (objFileSys.FileExists(PathTLW)) Then
Msgbox PathTLW & TLWArgs
Else
Msgbox PathTLW
End If
objShell.run PathTIE & TIEArgs,1,False
objShell.run PathTLW & TLWArgs,1,False
ElseIf OSBit = "32" Then
Set objShell = CreateObject("WScript.Shell")
PathTIE = chr(34) & "C:\Program Files\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" & chr(34)
If (objFileSys.FileExists(PathTIE)) Then
Msgbox PathTIE & TIEArgs
Else
Msgbox PathTIE
End If
PathTLW = chr(34) & "C:\Program Files\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" & chr(34)
If (objFileSys.FileExists(PathTLW)) Then
Msgbox PathTLW & TLWArgs
Else
Msgbox PathTLW
End If
objShell.run PathTIE & TIEArgs,1,False
objShell.run PathTLW & TLWArgs,1,False
Else
Msgbox "Error! No OS bit-level detected."
End If

Strange, huh?

0

Share this post


Link to post
Share on other sites

1:\ If you where to place this at the top of the script Set objShell = CreateObject("WScript.Shell") you

would only need 1 instead of the 3 you have.

2:\ Here is another way to check if it X86 orX64 Os


Dim SysVar : Set SysVar = Act.Environment("System")

If Right(SysVar("PROCESSOR_ARCHITECTURE"),2) = "64" Then
WScript.Echo "64 Bit Os : " & SysVar("PROCESSOR_ARCHITECTURE")
Else
WScript.Echo "32 Bit Os : " & SysVar("PROCESSOR_ARCHITECTURE")
End If

Produced this result 64 Bit Os : AMD64

3:\ it would be better to make a new Variable for this path, doing it the way you have it means you would

have to change 4 things if the path changes. Using a variable means only changing one path for the whole

script.


Dim aPath :aPath=Chr(34) & "C:\Program Files\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" & Chr(34)

0

Share this post


Link to post
Share on other sites

Sorry, but I don't think that this is a valid test for OS "bitness":

2:\ Here is another way to check if it X86 orX64 Os


Dim SysVar : Set SysVar = Act.Environment("System")

If Right(SysVar("PROCESSOR_ARCHITECTURE"),2) = "64" Then
WScript.Echo "64 Bit Os : " & SysVar("PROCESSOR_ARCHITECTURE")
Else
WScript.Echo "32 Bit Os : " & SysVar("PROCESSOR_ARCHITECTURE")
End If

Produced this result 64 Bit Os : AMD64

since you can have a 32-bit OS installed on a 64-bit capable processor.

A more accurate test (in batch, but can obviously be easily changed to the script language of your choice), is:


SET "xOS=x64"& IF /I "%PROCESSOR_ARCHITECTURE%"=="x86" (IF NOT DEFINED PROCESSOR_ARCHITEW6432 SET "xOS=x86")
ECHO %xOS%

A discussion on detecting the OS "bitness", along with reference links, can be found here.

Cheers and Regards

0

Share this post


Link to post
Share on other sites
Sorry, but I don't think that this is a valid test for OS "bitness":

Can you read I said another way, as to how the poster posted, I never said the most accurate.

If (objFileSys.FolderExists("C:\Program Files (x86)")) Then

Here is a accurate ways of doing it, only valid on Vista and up

This get the architecture of the operating system, as opposed to that of the processor.


Dim Wmi :Set Wmi = GetObject("winmgmts:\\.\root\CIMV2")
Dim Obj

For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_OperatingSystem")
MsgBox Obj.OSArchitecture
Next

Another way to get the processor architecture used by the platform code


Dim Wmi :Set Wmi = GetObject("winmgmts:\\.\root\CIMV2")
Dim Obj, Var
For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_Processor")
Select Case Obj.Architecture
Case 0 : Var = "x86"
Case 1 : Var = "Mips"
Case 2 : Var = "Alpha"
Case 3 : Var = "PowerPc"
Case 5 : Var = "Arm"
Case 6 : Var = "Itanium-based systems"
Case 9 : Var = "x64"
End Select
Next
MsgBox "Architecture Type : " & Var

Another way this will return 32 Bit on a x86 OS and this 64 bit on X64 OS


Dim Wmi :Set Wmi = GetObject("winmgmts:\\.\root\CIMV2")
For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_Processor")
MsgBox "Os Bit : " & Obj.AddressWidth
Next

I did not known about PROCESSOR_ARCHITEW6432, but using it returns 32 Bit Os : AMD64, I

am on X64 Windows 7 Ultimate


Dim SysVar : Set SysVar = Act.Environment("System")
'PROCESSOR_ARCHITECTURE
If Right(SysVar("PROCESSOR_ARCHITEW6432"),2) = "64" Then
WScript.Echo "64 Bit Os : " & SysVar("PROCESSOR_ARCHITECTURE")
Else
WScript.Echo "32 Bit Os : " & SysVar("PROCESSOR_ARCHITECTURE")
End If

Script Results

0

Share this post


Link to post
Share on other sites

Yes, using PROCESSOR_ARCHITEW6432 is tricky, and its value is only valid when used together with PROCESSOR_ARCHITECTURE as described by David Wang at MS, whom everyone seems to refer to on the matter:

Detection Matrix

The general idea is to check the following environment variables:

  • PROCESSOR_ARCHITECTURE - reports the native processor architecture EXCEPT for WOW64, where it reports x86.
  • PROCESSOR_ARCHITEW6432 - not used EXCEPT for WOW64, where it reports the original native processor architecture.

Visually, it looks like:


Environment Variable \ Program Bitness 32bit Native 64bit Native WOW64
PROCESSOR_ARCHITECTURE x86 AMD64 x86
PROCESSOR_ARCHITEW6432 undefined undefined AMD64

  • WOW64 = 32bit Program on 64bit OS
  • Replace AMD64 with IA64 for Itaniums

Detection Logic

The logic that I use from a program to detect whether the OS is 32bit or 64bit looks like this:

IF PROCESSOR_ARCHITECTURE == amd64 OR

PROCESSOR_ARCHITEW6432 == amd64 THEN

// OS is 64bit

ELSE

// OS is 32bit

END IF

Another way to test for the same thing is:

IF PROCESSOR_ARCHITECTURE == x86 AND

PROCESSOR_ARCHITEW6432 NOT DEFINED THEN

// OS is 32bit

ELSE

// OS is 64bit

END IF

0

Share this post


Link to post
Share on other sites

My point was PROCESSOR_ARCHITEW6432 can not be used in VBS script,

it return "" or 0 character length in VBS

Example VBS


Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim SysVar : Set SysVar = Act.Environment("System")

If SysVar("PROCESSOR_ARCHITEW6432") = "" Then
WScript.Echo "Empty Value No Information Test 1"
Else
WScript.Echo "Type : " & SysVar("PROCESSOR_ARCHITEW6432")
End If

If Len(SysVar("PROCESSOR_ARCHITEW6432")) = 0 Then
WScript.Echo "Empty Value No Information Test 2"
Else
WScript.Echo "Type : " & SysVar("PROCESSOR_ARCHITEW6432")
End If

Returns

Empty Value No Information Test 1

Empty Value No Information Test 2

0

Share this post


Link to post
Share on other sites

My point was PROCESSOR_ARCHITEW6432 can not be used in VBS script,

it return "" or 0 character length in VBS

Example VBS


Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim SysVar : Set SysVar = Act.Environment("System")

If SysVar("PROCESSOR_ARCHITEW6432") = "" Then
WScript.Echo "Empty Value No Information Test 1"
Else
WScript.Echo "Type : " & SysVar("PROCESSOR_ARCHITEW6432")
End If

If Len(SysVar("PROCESSOR_ARCHITEW6432")) = 0 Then
WScript.Echo "Empty Value No Information Test 2"
Else
WScript.Echo "Type : " & SysVar("PROCESSOR_ARCHITEW6432")
End If

Returns

Empty Value No Information Test 1

Empty Value No Information Test 2

For your tests that is probably correct. PROCESSOR_ARCHITEW6432 is only defined at all if and only if you are on a 64-bit OS AND you are running a 32-bit process at that instant, in other words if you are running a 32-bit app. In that one particular circumstance it will be equal to "AMD64", if you are on a 64-bit OS, otherwise its value is undefined so you will get the empty zero length value that you got. But its value is important to check for since in that same unique circumstance that PROCESSOR_ARCHITEW6432 is defined, PROCESSOR_ARCHITECTURE will be equal to "x86" even though you are running a 64-bit OS on a 64-bit processor. I'm not sure how you can force that condition for your VBS test.

Cheers and Regards

0

Share this post


Link to post
Share on other sites

I think gunsmokingman method using Obj.AddressWidth is good enough. (post #9)

Here is another one liner code using Obj.AddressWidth I found.

The importance of checking bitness is to know the OS's bitness, not CPU bitness.

Correct me if I'm wrong, since we can't install x64 OS when CPU is only 32-bit-capable, it makes sense to check OS bitness only.

As I also noted, INF has .NTx86, .ntamd64, .ntia64 or .nt section

These sections are purely base on OS bitness.

Hence what is important during installation is the OS's bitness, not CPU's bitness.

For the OP initial problem ("Cannot find the file specified"), I think we can simply further using oShell.CurrentDirectory (like cmd pushd command)

Just my thought...

0

Share this post


Link to post
Share on other sites

PROCESSOR_ARCHITECTURE will be equal to "x86" even though you are running a 64-bit OS on a 64-bit processor.

Wrong notice the script report AMD64, a script using WmiCodeCreator report 64 , System Properties show 64 Bit Os

post-5386-0-76549300-1362289334_thumb.pn

Geej is correct read what the MSDN AddressWidth is for

0

Share this post


Link to post
Share on other sites

PROCESSOR_ARCHITECTURE will be equal to "x86" even though you are running a 64-bit OS on a 64-bit processor.

Wrong notice the script report AMD64, a script using WmiCodeCreator report 64 , System Properties show 64 Bit Os

post-5386-0-76549300-1362289334_thumb.pn

Geej is correct read what the MSDN AddressWidth is for

How was that wrong? I would interpret your script results to mean that you were running a 64-bit process.

And I do not disagree with Geej. Actually, I won't disagree with either one of you. You both know far more about VBScript that I do. I was just passing along the info and definition of the system variables and how to use them to get the OS bitness directly from MS. It wouldn't be the first time that MS was wrong, but I don't think they are in this case.

Cheers and Regards

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.