# VBScript Problem Again

**URL:** https://www.finalbuilder.com/forums/t/vbscript-problem-again/4304
**Category:** Discussion
**Created:** [March 25, 2008, 2:32am UTC](https://www.finalbuilder.com/forums/t/vbscript-problem-again/4304 "2008-03-25T02:32:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ipfservicedelivery](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/i/f07891/32.png) [@ipfservicedelivery](https://www.finalbuilder.com/forums/u/ipfservicedelivery)
#### Post date: [March 25, 2008, 2:32am UTC](https://www.finalbuilder.com/forums/t/vbscript-problem-again/4304/1 "2008-03-25T02:32:06Z")

</div>

Hi Guys,

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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

&nbsp;

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  
&nbsp;&nbsp;&nbsp; strText = objTextFile2.ReadLine  
&nbsp;&nbsp;&nbsp; If Instr(strText,"Online") Then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NewLine = Mid(strText,3,6)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objTextFile1.Write "select " & NewLine & VbCrLf  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objTextFile1.Write "detail disk" & VbCrLF  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; 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  
&nbsp;&nbsp;&nbsp; strText = objTextFile4.ReadLine  
&nbsp;&nbsp;&nbsp; If Instr(strText,"LUN ID") Or Instr(strText,"Partition") Then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objTextFile3.WriteLine strText  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; 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  
&nbsp;&nbsp;&nbsp; strNextLine = objTextFile5.Readline  
&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; lunID = Instr(strNextLine,LUN1)  
&nbsp;&nbsp;&nbsp; If lunID \<\> 0 Then  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strNextLine = objTextFile5.ReadLine  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strVolume = "Select " & Mid(strNextLine,3,8)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objTextFile6.WriteLine strVolume  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objTextFile6.WriteLine "Assign letter=" & LETTER1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'WScript.Echo strNextLine  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'WScript.Quit(1)  
&nbsp;&nbsp;&nbsp; End IF

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

Loop

&nbsp;

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [March 25, 2008, 3:28am UTC](https://www.finalbuilder.com/forums/t/vbscript-problem-again/4304/2 "2008-03-25T03:28:21Z")

</div>

(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](http://www.ntwizards.net/2006/12/29/windows-x64-annoyances)   
  
 - Angus

---

<div class="post-metadata">

### Author: ![ipfservicedelivery](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/i/f07891/32.png) [@ipfservicedelivery](https://www.finalbuilder.com/forums/u/ipfservicedelivery)
#### Post date: [March 31, 2008, 9:11am UTC](https://www.finalbuilder.com/forums/t/vbscript-problem-again/4304/3 "2008-03-31T09:11:16Z")

</div>

Thanks Angus this resolved the problem.
