Jump to content

Need help for a VBS script


krovax

Recommended Posts

Hi guys, I'm a total newb in scripting and I hae the following need:

I want to use Winpe 2.0 to wipe hardrive with diskpart and have a log of that. I want my log file to have the serial number of the drive as file name.

I know that there is no good way to get the serial number of HDD (IDE or SATA) so I am using a bar code reader.

The script should pop a text box so I can scan the serial number on the hard drive and keep that value to name my log file. here is a script someone made from me but we are unable to find what it's not working:

Dim Reponse

Dim AbsPath:AbsPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "") ' This variable DOES have a trailing '\'

Reponse = inputbox("write a value,Cancel or no value to exit the script","Diskpart")

If Answer = "" Then

Wscript.Quit

End if

Call ExecuteProg(AbsPath & "diskpart ", Answer)

Sub ExecuteProg(PathAndProgName, Var1)

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run PathAndProgName & "/s diskpart.txt>z:\" & Var1 & ".txt"

End sub

(there was a bit of french in here so I tried to rename it to english)

in my startnet.cmd there is a command to map a drive to a network share then I am running the vbs.

The vbs is supposed to start diskpart, run the script, and redirect the output to the mapped drive and use the value as a log file name.

Now when we execute the vbs dispart is running but it's not using the the clean all command that he is supposed to do and there is no log file created.

Thx for your help and don't be shy to ask me question if there is something bizarre (english is my second language so I'm trying to be as clear as I can)

Link to comment
Share on other sites


This is my problem, I don't have any error.

Just wanted to see if the script was looking fine (cause like I said I am a total nub in vbs).

The only thing I can see is that there is another command prompt opening and there is a dispart display then it shutdown and nothing more, not even a log is created. The dispart cclean all command should take about 10 minutes and I should have a log on my mapped drive.

Edited by krovax
Link to comment
Share on other sites

I would do something different for the choice box,

something like

choice=MsgBox("Do you want to run diskpart now?",3,"Run diskpart?")

If choice = 6 Then
Call ExecuteProg(AbsPath & "diskpart ", Answer)

End If

Edited by jondercik
Link to comment
Share on other sites

Unless you are going to call the same diskpart script multiple times on the same machine there is no need for a subroutine. Also your variable name keeps changing. The value from your input box is put into 'Response' but then you check the value for input by looking at 'Answer' and then try naming the file using 'Var1'. These should all point to the same variable name.

Dim Reponse
Dim AbsPath
Dim Answer
Dim WshShell

Set WshShell = WScript.CreateObject("WScript.Shell")

Answer = ""
AbsPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")

Answer = inputbox("write a value,Cancel or no value to exit the script","Diskpart")

If Answer = "" Then
Wscript.Quit
End if

WshShell.Run AbsPath & "diskpart.exe /s diskpart.txt>z:\" & Answer & ".txt"

Link to comment
Share on other sites

And how yould you guys write what I want?

Input box, take that value entered and use it in that way diskpart /s diskpart.txt>z:\"value".txt

*I didn't refresh before posting, sorry

Edited by krovax
Link to comment
Share on other sites

Still same problem, the script start, another windows open and close really fast and there is no text file create on the share and no error message.

If anyone have an idea of how we could correct that or do it another way that would be awesome :)

I was thinking that maybe I could save the file on the ram drive (x:) into "value".qwe and then copy *.qwe on z:

What do you guys think of that?

Edited by krovax
Link to comment
Share on other sites

Yes I have tried that before but my problem was that I had to give a name for the log file and it was always the same name.

I know I could have change the name after but when I will wipe 10 HDD at the same time all my file will write over each other.

Link to comment
Share on other sites

try this

Dim Reponse
Dim AbsPath
Dim Answer
Dim WshShell

Set WshShell = WScript.CreateObject("WScript.Shell")

Answer = ""
AbsPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")

Answer = inputbox("write a value,Cancel or no value to exit the script","Diskpart")

If Answer = "" Then
Wscript.Quit
End if

WshShell.Run "cmd /k " & chr(34) & abspath & "diskpart.exe" & chr(34) & " /s diskpart.txt>c:\" & Answer & ".txt"

Link to comment
Share on other sites

Woot!!!!!!!!

When I tried the last script it didn't worked (I had no access to c:) but then I changed the path to Z: and the file was there.

Thank you so much guys!!!!

For my personnal learning, what is abspath? and how to work with it?

Link to comment
Share on other sites

I wouldnt use the following line, I would, and actually do the following

DONT USE

AbsPath = Replace(WScript.ScriptFullName, WScript.ScriptName, "")

Use

currentDirectory = WshShell.currentDirectory & "\"

Just my two cents

Jim

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...