VBScript Problem Again

Hi Guys,

              I have another issue with trying to run a VBScript from within Automise, I know I am probably missing something simple again but I have tried various ways of trying to get it to work but i'm lost on this one. I am trying to run the following code from OnExecute again ( I know about any Subs or Functions having to placed in the Global Project). It does work if I call it from the command line within a .vbs script.

CONST LUN1 = 58
CONST LUN2 = 59
CONST LETTER1 = "X"
CONST LETTER2 = "Y"
Const ForReading = 1

 

Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set objShell = Wscript.CreateObject("Wscript.Shell")
objName = objFSO.GetTempName
objTempFile = objName
objShell.Run "cmd /c diskpart /s c:\Automise\listdisks.txt >" & objTempFile, 0, True

objName1 = objFSO.GetTempName
objTempFile1 = objName1
Set objTextFile1 = objFSO.CreateTextFile(objTempFile1, 2)

Set objTextFile2 = objFSO.OpenTextFile(objTempFile, 1)
Do Until objTextFile2.AtEndOfStream
    strText = objTextFile2.ReadLine
    If Instr(strText,"Online") Then
        NewLine = Mid(strText,3,6)
        objTextFile1.Write "select " & NewLine & VbCrLf
        objTextFile1.Write "detail disk" & VbCrLF
       
    End If
Loop
objTextFile1.Close
objTextFile2.Close

objName2 = objFSO.GetTempName
objTempFile2 = objName2
objShell.Run "cmd /c diskpart /s c:\Automise\" & objTempFile1 &">" & objTempFile2, 0, True

objName3 = objFSO.GetTempName
objTempFile3 = objName3
Set objTextFile3 = objFSO.CreateTextFile(objTempFile3, 2)

Set objTextFile4 = objFSO.OpenTextFile(objTempFile2, 1)

Do Until objTextFile4.AtEndOfStream
    strText = objTextFile4.ReadLine
    If Instr(strText,"LUN ID") Or Instr(strText,"Partition") Then
        objTextFile3.WriteLine strText
       
    End If
Loop

objName4 = objFSO.GetTempName
objTempFile4 = objName4

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile5 = objFSO.OpenTextFile (objTempFile3, ForReading)
Set ObjTextFile6 = objFSO.CreateTextFile(objTempFile4, ForWriting)

Do Until objTextFile5.AtEndOfStream
    strNextLine = objTextFile5.Readline
   
    lunID = Instr(strNextLine,LUN1)
    If lunID <> 0 Then
       strNextLine = objTextFile5.ReadLine
       strVolume = "Select " & Mid(strNextLine,3,8)
       objTextFile6.WriteLine strVolume
       objTextFile6.WriteLine "Assign letter=" & LETTER1
       'WScript.Echo strNextLine
       'WScript.Quit(1)
    End IF

    lunID = Instr(strNextLine,LUN2)
    If lunID <> 0 Then
       strNextLine = objTextFile5.ReadLine
       strVolume = "Select " & Mid(strNextLine,3,8)
       objTextFile6.WriteLine strVolume
       objTextFile6.WriteLine "Assign letter=" & LETTER2
       'WScript.Echo strNextLine
       'WScript.Quit(1)
    End IF

Loop

 

(Just an update for future reference.)

We worked through this and resolved it in the chat room. The problem is that on x64 Windows, diskpart.exe is a 32-bit-only application and can’t be accessed.

The quick and easy workaround is to use Explorer to copy diskpart.exe from the Windows\System32 directory to the Windows\SysWow64 directory. Then it works fine.

For more information on directory redirecting in 64-bit Windows, see here: http://www.ntwizards.net/2006/12/29/windows-x64-annoyances

- Angus

Thanks Angus this resolved the problem.