Results 1 to 15 of 15

Thread: [RESOLVED] Cant run VBS script over Application

  1. #1

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Resolved [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!

  2. #2
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: Cant run VBS script over Application

    Quote Originally Posted by beic View Post

    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.

  3. #3

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Cant run VBS script over Application

    Quote Originally Posted by OptionBase1 View Post
    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.

  4. #4
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    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.
    Last edited by OptionBase1; Aug 26th, 2023 at 04:26 PM.

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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

  6. #6

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Cant run VBS script over Application

    Quote Originally Posted by OptionBase1 View Post
    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?

  7. #7
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: Cant run VBS script over Application

    Quote Originally Posted by beic View Post
    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

  8. #8

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Cant run VBS script over Application

    Quote Originally Posted by dilettante View Post
    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

  9. #9

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Cant run VBS script over Application

    Quote Originally Posted by OptionBase1 View Post
    You could try C:\Windows\SysNative\DISM.exe
    You meant C:\Windows\SysWow64\DISM.exe ?

  10. #10
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,622

    Question Re: Cant run VBS script over Application

    Why don't you run DISM directly without going through cmd.exe first?

  11. #11
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,630

    Re: Cant run VBS script over Application

    Quote Originally Posted by beic View Post
    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.

  12. #12

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Cant run VBS script over Application

    Quote Originally Posted by VanGoghGaming View Post
    Why don't you run DISM directly without going through cmd.exe first?
    It wont run either like that.

  13. #13

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Cant run VBS script over Application

    Quote Originally Posted by OptionBase1 View Post
    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!

  14. #14
    Addicted Member
    Join Date
    May 2012
    Location
    42.787034,-81.176367
    Posts
    197

    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

  15. #15

    Thread Starter
    Addicted Member beic's Avatar
    Join Date
    Jun 2012
    Posts
    176

    Re: Cant run VBS script over Application

    Quote Originally Posted by Joe Caverly View Post
    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!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width