[RESOLVED] Cant run VBS script over Application
Hi there,
I'm trying to run external CMD over VBS code inside VB6 application, but I got error message:
Code:
Error: 11
You cannot service a running 64-bit operating system with a 32-bit version of DISM.
Please use the version of DISM that corresponds to your computer's architecture.
The code follows:
Code:
Call RunCmd2("DISM /Online /Cleanup-Image /ScanHealth")
Code:
Public Sub RunCmd2(stCmd As String)
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "cmd.exe", "/k " & stCmd, "", "runas", 1
Set objShell = Nothing
Exit Sub
End Sub
I'm using VB6 on Microsoft Windows 7 64-bit edition.
Any help / suggestions would be appreciated! ;)
Re: Cant run VBS script over Application
Quote:
Originally Posted by
beic
Code:
Error: 11
You cannot service a running 64-bit operating system with a 32-bit version of DISM.
Please use the version of DISM that corresponds to your computer's architecture.
I'm using VB6 on Microsoft Windows 7 64-bit edition.
Any help / suggestions would be appreciated! ;)
Follow the very clear instructions given in the first error message you posted.
Re: Cant run VBS script over Application
Quote:
Originally Posted by
OptionBase1
Follow the very clear instructions given in the first error message you posted.
I tried with:
Code:
Call RunCmd2("C:\Windows\system32\DISM.exe /Online /Cleanup-Image /ScanHealth")
Code:
Public Sub RunCmd2(stCmd As String)
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "C:\Windows\system32\cmd.exe", "/k " & stCmd, "", "runas", 1
Set objShell = Nothing
Exit Sub
End Sub
But I got the same result.
Re: Cant run VBS script over Application
Sorry, I didn't catch that this was a Windows utility, I thought it was just some random 32-bit exe that you were trying to run.
Re: Cant run VBS script over Application
Yeah, this isn't a VB6 programming issue. You can't get around it by doing anything different in VB6.
I'm not sure why an application would ever be trying to perform these kinds of administrative actions. You'd normally only run Deployment Image Servicing and Management from a Command Prompt or "PowerShell" script.
Not only does this command line tool come in separate 32- and 64-bit versions, there are different versions that work in different Windows versions.
https://learn.microsoft.com/en-us/wi...iew=windows-11
Re: Cant run VBS script over Application
Quote:
Originally Posted by
OptionBase1
Of course you did. Did you read the error message?
I'm running 64-bit Windows, so, "C:\Windows\system32\DISM.exe" should correspond to the 64-bit architecture path, or did I miss something?
Re: Cant run VBS script over Application
Quote:
Originally Posted by
beic
I'm running 64-bit Windows, so, "C:\Windows\system32\DISM.exe" should correspond to the 64-bit architecture path, or did I miss something?
You could try C:\Windows\SysNative\DISM.exe
Re: Cant run VBS script over Application
Quote:
Originally Posted by
dilettante
Yeah, this isn't a VB6 programming issue. You can't get around it by doing anything different in VB6.
I'm not sure why an application would ever be trying to perform these kinds of administrative actions. You'd normally only run Deployment Image Servicing and Management from a Command Prompt or "PowerShell" script.
Not only does this command line tool come in separate 32- and 64-bit versions, there are different versions that work in different Windows versions.
https://learn.microsoft.com/en-us/wi...iew=windows-11
I don't know about that, but if you paste this code into "test.vbs" file and run it, it will execute as it should...
Code:
Dim objShell
Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "cmd.exe", "/k " & "DISM.exe /Online /Cleanup-Image /ScanHealth", "", "runas", 1
Re: Cant run VBS script over Application
Quote:
Originally Posted by
OptionBase1
You could try C:\Windows\SysNative\DISM.exe
You meant C:\Windows\SysWow64\DISM.exe ?
Re: Cant run VBS script over Application
Why don't you run DISM directly without going through cmd.exe first?
Re: Cant run VBS script over Application
Quote:
Originally Posted by
beic
You meant C:\Windows\SysWow64\DISM.exe ?
Nope, I meant exactly what I posted. Did you try it? SysNative is an alias that allows a 32 bit application to access the 64 bit System files.
Re: Cant run VBS script over Application
Quote:
Originally Posted by
VanGoghGaming
Why don't you run DISM directly without going through cmd.exe first?
It wont run either like that.
Re: Cant run VBS script over Application
Quote:
Originally Posted by
OptionBase1
Nope, I meant exactly what I posted. Did you try it? SysNative is an alias that allows a 32 bit application to access the 64 bit System files.
How is this possible in real case? I know of course about System, System32 and SysWow64 paths, but never heard about "virtual" SysNative path!
So, basically, SysNative is only available on 64-bit systems and above Windows 7 (Vista) ?
Btw, it's working, thank you! ;)
Re: Cant run VBS script over Application
Note well that running cmd.exe via shell from VB6 will always run the 32-bit cmd.exe.
Code:
Option Explicit
Private Sub Form_Load()
Dim stCmd As String
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
stCmd = "echo %PROCESSOR_ARCHITECTURE%"
' Results from running on my;
' Windows 10 X64
' VB6 SP6
objShell.ShellExecute "C:\Windows\system32\cmd.exe", "/k " & stCmd, "", "runas", 1
'Returns x86
objShell.ShellExecute "C:\Windows\sysnative\cmd.exe", "/k " & stCmd, "", "runas", 1
'Returns AMD64
objShell.ShellExecute "C:\Windows\syswow64\cmd.exe", "/k " & stCmd, "", "runas", 1
'Returns x86
Set objShell = Nothing
Unload Me
End Sub
Thus, I've always been explicit in the version of cmd.exe that I shell to.
Joe
Ref: The 'Sysnative' folder in 64-bit Windows explained
Ref: How-to: Detecting 64 bit vs 32 bit
Re: Cant run VBS script over Application
Quote:
Originally Posted by
Joe Caverly
Note well that running
cmd.exe via shell from VB6 will always run the 32-bit
cmd.exe.
Code:
Option Explicit
Private Sub Form_Load()
Dim stCmd As String
Dim objShell As Object
Set objShell = CreateObject("Shell.Application")
stCmd = "echo %PROCESSOR_ARCHITECTURE%"
' Results from running on my;
' Windows 10 X64
' VB6 SP6
objShell.ShellExecute "C:\Windows\system32\cmd.exe", "/k " & stCmd, "", "runas", 1
'Returns x86
objShell.ShellExecute "C:\Windows\sysnative\cmd.exe", "/k " & stCmd, "", "runas", 1
'Returns AMD64
objShell.ShellExecute "C:\Windows\syswow64\cmd.exe", "/k " & stCmd, "", "runas", 1
'Returns x86
Set objShell = Nothing
Unload Me
End Sub
Thus, I've always been explicit in the version of
cmd.exe that I shell to.
Joe
Ref:
The 'Sysnative' folder in 64-bit Windows explained
Ref:
How-to: Detecting 64 bit vs 32 bit
Thank you for the explanation example! ;)