Falcor Posted March 1, 2013 Posted March 1, 2013 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 returnsC:\Program Files (x86)On 32-bit machines, it returnsC:\Program FilesHowever, 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,FalsePathTIE = 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,FalseI 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!
Yzöwl Posted March 1, 2013 Posted March 1, 2013 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)
Falcor Posted March 1, 2013 Author Posted March 1, 2013 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.
Falcor Posted March 1, 2013 Author Posted March 1, 2013 This seems to be a problem read this ThreadThis 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, PathTLWSet objFileSys = CreateObject("Scripting.FileSystemObject")If (objFileSys.FolderExists("C:\Program Files (x86)")) Then OSBit = "64"Else OSBit = "32"End IfIf 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,FalseElseIf 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,FalseElse Msgbox "Error! No OS bit-level detected."End IfThis 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.
Falcor Posted March 1, 2013 Author Posted March 1, 2013 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, TLWArgsTIEArgs = " -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 IfIf 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,FalseElseIf 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,FalseElse Msgbox "Error! No OS bit-level detected."End IfStrange, huh?
gunsmokingman Posted March 1, 2013 Posted March 1, 2013 1:\ If you where to place this at the top of the script Set objShell = CreateObject("WScript.Shell") youwould only need 1 instead of the 3 you have.2:\ Here is another way to check if it X86 orX64 OsDim 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 IfProduced this result 64 Bit Os : AMD643:\ it would be better to make a new Variable for this path, doing it the way you have it means you wouldhave to change 4 things if the path changes. Using a variable means only changing one path for the wholescript. Dim aPath :aPath=Chr(34) & "C:\Program Files\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" & Chr(34)
bphlpt Posted March 2, 2013 Posted March 2, 2013 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 OsDim 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 IfProduced this result 64 Bit Os : AMD64since 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
gunsmokingman Posted March 2, 2013 Posted March 2, 2013 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)")) ThenHere is a accurate ways of doing it, only valid on Vista and upThis 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 NextAnother way to get the processor architecture used by the platform codeDim 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 OSDim 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, Iam on X64 Windows 7 UltimateDim 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
bphlpt Posted March 2, 2013 Posted March 2, 2013 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 MatrixThe 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 WOW64PROCESSOR_ARCHITECTURE x86 AMD64 x86PROCESSOR_ARCHITEW6432 undefined undefined AMD64WOW64 = 32bit Program on 64bit OSReplace AMD64 with IA64 for ItaniumsDetection LogicThe 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 64bitELSE // OS is 32bitEND IFAnother way to test for the same thing is:IF PROCESSOR_ARCHITECTURE == x86 AND PROCESSOR_ARCHITEW6432 NOT DEFINED THEN // OS is 32bitELSE // OS is 64bitEND IF
gunsmokingman Posted March 3, 2013 Posted March 3, 2013 My point was PROCESSOR_ARCHITEW6432 can not be used in VBS script,it return "" or 0 character length in VBSExample VBSDim 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 ReturnsEmpty Value No Information Test 1Empty Value No Information Test 2
bphlpt Posted March 3, 2013 Posted March 3, 2013 My point was PROCESSOR_ARCHITEW6432 can not be used in VBS script,it return "" or 0 character length in VBSExample VBSDim 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 ReturnsEmpty Value No Information Test 1Empty Value No Information Test 2For 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
Geej Posted March 3, 2013 Posted March 3, 2013 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 sectionThese 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...
gunsmokingman Posted March 3, 2013 Posted March 3, 2013 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 OsGeej is correct read what the MSDN AddressWidth is for
bphlpt Posted March 3, 2013 Posted March 3, 2013 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 OsGeej is correct read what the MSDN AddressWidth is forHow 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
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now