Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Problem with simple VBScript ported to Windows 7  (Read 10568 times)

0 Members and 1 Guest are viewing this topic.

John_L.

    Topic Starter


    Rookie

    Thanked: 2
    • Experience: Experienced
    • OS: Windows XP
    Problem with simple VBScript ported to Windows 7
    « on: January 16, 2015, 02:16:51 PM »
    I think I obtained this useful piece of .bat code from a Computer Hope forum. I use it regularly on Windows XP.

    Code: [Select]
    :GetPassword
    pushd %tmp%
    >p.vbs echo WSH.Echo CreateObject("ScriptPW.Password").GetPassword
    for /F usebackq %%a in (`cscript //Nologo p.vbs`) do set %1=%%a
    del p.vbs
    popd

    However, it fails when ported to Windows 7 with the following error message:

    C:\Users\John\AppData\Local\Temp\p.vbs(1, 1) Microsoft VBScript runtime error: A
    ctiveX component can't create object: 'ScriptPW.Password'


    Thanks in advance for any help you may be able to provide.

    Salmon Trout

    • Guest
    Re: Problem with simple VBScript ported to Windows 7
    « Reply #1 on: January 16, 2015, 02:35:06 PM »
    Are you running 64 bit Windows 7? if so, you may need to run the vbs with the 32 bit Cscript engine.


    John_L.

      Topic Starter


      Rookie

      Thanked: 2
      • Experience: Experienced
      • OS: Windows XP
      Re: Problem with simple VBScript ported to Windows 7
      « Reply #2 on: January 16, 2015, 03:54:56 PM »
      I am running 64-bit Windows, but the only cscript.exe I see is in C:\WINDOWS\System32\.

      Thanks again.

      Salmon Trout

      • Guest
      Re: Problem with simple VBScript ported to Windows 7
      « Reply #3 on: January 16, 2015, 04:44:45 PM »
      It's nothing to do with 32 or 64 bit, I have found. Your problem is the ScriptPW.Password object was removed in Vista and later Windows versions. I have read suggestions to copy scriptpw.dll over and register it, but I have not done this. YMMV. You may have to find a workaround. If you are able to use 3rd party software, here is an example:

      http://blog.magerquark.de/scriptpw-dll-on-windows-2008-and-windows-7-scriptpw-password/

      You could have got all this information by Googling "ScriptPW.Password Windows 7"


      Salmon Trout

      • Guest
      Re: Problem with simple VBScript ported to Windows 7
      « Reply #4 on: January 17, 2015, 07:10:53 AM »
      This seems to work, using the Powershell securestring input method instead of vbscript; the only difference is that the Powershell method input echoes one asterisk to the console for each character entered, whereas the old (pre-Vista era) ScriptPW.Password method echoed nothing.

      Code: [Select]
      :GetPassword
      pushd %tmp%
      >  pwd.ps1 Echo $Password = Read-Host -assecurestring
      >> pwd.ps1 Echo $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
      >> pwd.ps1 Echo $PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
      >> pwd.ps1 Echo Write-Host $PlainPassword
      for /f "delims=" %%a in ('Powershell -executionpolicy remotesigned -File pwd.ps1') do set %1=%%a
      del pwd.ps1
      popd
      « Last Edit: January 17, 2015, 07:26:08 AM by Salmon Trout »

      Salmon Trout

      • Guest
      Re: Problem with simple VBScript ported to Windows 7
      « Reply #5 on: January 17, 2015, 07:50:12 AM »
      I am running 64-bit Windows, but the only cscript.exe I see is in C:\WINDOWS\System32\

      The subject is too big for me to explain it here, but you possibly should read up on the subject of "Windows On Windows 64" ("WoW64"). 64 bit Windows contains both 64 bit and 32 bit versions of certain system files. The 64 bit versions are in  %SystemRoot%\system32 and the 32 bit versions are in %SystemRoot%\SysWoW64. In these 2 folders you will find 64 and 32 bit versions of many Windows executables and program files, including cmd.exe, cscript.exe, wscript.exe etc. WOW64 is a compatibility layer enabling a 64 bit OS on 64 bit hardware to run 32 bit programs transparently. Most of the time there is no need to become aware of it, but occasionally you have to force things, for example there are lots of 32 bit COM objects which 64 bit vbscript engines (cscript and wscript) cannot run. Since the default environment on a 64 bit OS is the 64 bit version, sometimes you have to force the 32 bit engine to make the old scripts work, (by explicitly calling the SysWoW64 version) which is why I wondered about this (above) although it turned out top be a red herring.

      Example article here

      http://en.wikipedia.org/wiki/WoW64