This is the example, a shortcut was installed to this code
:
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
' $Header: C:/DBAREIS/Projects.PVCS/Win32/ScriptingTipsAndTricks/EXAMPLE[vbs].GetEnv() [Get Environment Variables].vbs.txt.pvcs 1.0 11 Jul 2014 19:31:06 USER "Dennis" $
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
dim oShell : set oShell = CreateObject("WScript.Shell")
TEST_SHOW_MODE("Script Starting")
RestartCscriptIn32BitModeIfRequired()
TEST_SHOW_MODE("Script Initialized/Finishing")
set oShell = Nothing
wscript.quit 777
'============================================================================
sub RestartCscriptIn32BitModeIfRequired()
' Based on FIXED code: http://stackoverflow.com/questions/2806584/how-do-i-run-a-vbscript-in-32-bit-mode-on-a-64-bit-machine
'============================================================================
Dim r32wShell, r32env1, r32env2, r32iCount
Dim r32fso
SET r32fso = CreateObject("Scripting.FileSystemObject")
Set r32wShell = CreateObject("WScript.Shell")
r32env1 = r32wShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
If r32env1 <> "x86" Then
'--- not running in x86 mode (prevent infinite loops) ---------------
For r32iCount = 0 To WScript.Arguments.Count - 1
r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
Next
If InStr(r32env2, "restart32") <> 0 Then
'--- Already tried to restart -----------------------------------
MsgBox "Cannot find 32bit version of cscript.exe or unknown OS type " & r32env1
else
'--- Ok this is the first time so BUILD THE COMMAND WITHOUT SCRIPT PARAMETERS ---
dim strCMD, iCount
strCMD = r32wShell.ExpandEnvironmentStrings("%SYSTEMROOT%") & "\SysWOW64\cscript.exe"
if NOT r32fso.FileExists(strCMD) then
'--- This may not work if we can't find the SysWOW64 Version ---
strCMD = "cscript.exe"
end if
strCMD = strCMD & " //NoLogo """ & Wscript.ScriptFullName & """"
'--- Rebuild the arguments on the command ----------------------------
If Wscript.Arguments.Count > 0 Then
For iCount = 0 To WScript.Arguments.Count - 1
if Instr(Wscript.Arguments(iCount), " ") = 0 Then ' add unspaced args
strCMD = strCMD & " " & Wscript.Arguments(iCount) & " "
else
If Instr("/-\", Left(Wscript.Arguments(iCount), 1)) > 0 Then ' quote spaced args
If InStr(WScript.Arguments(iCount),"=") > 0 Then
strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") + 1) & """ "
ElseIf Instr(WScript.Arguments(iCount),":") > 0 Then
strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") + 1) & """ "
Else
strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
End If
Else
strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
End If
End If
Next
End If
'--- Start the command and flag that we restarted ---------------
wscript.echo "Restarting, you will not see stdout after this)..."
dim ScriptRc : ScriptRc = 9876
ScriptRc = r32wShell.Run(strCMD & " restart32", 0, true)
end if
Set r32wShell = Nothing
WScript.Quit( ScriptRc )
End If
Set r32wShell = Nothing
Set r32fso = Nothing
end sub
'============================================================================
sub TEST_SHOW_MODE(Doing)
'============================================================================
say "Mode: " & GetEnv("PROCESSOR_ARCHITECTURE") & " (" & Doing & ")"
MsgBox "Mode: " & GetEnv("PROCESSOR_ARCHITECTURE"),, Doing
end sub
'============================================================================
function GetEnv(EnvName)
'============================================================================
dim Try
Try = "%" & EnvName & "%"
GetEnv = oShell.ExpandEnvironmentStrings(Try)
if GetEnv = Try then
GetEnv = ""
end if
end function
'============================================================================
sub Say(What)
'============================================================================
wscript.echo What
end sub