Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Pass parameters in VBScript

- - - - -

  • Please log in to reply
12 replies to this topic

#1
randalldale

randalldale

    Member

  • Member
  • PipPip
  • 115 posts
  • Joined 16-November 04
Hi guys,

First thanks for all the help in the past.

A little background I have an image that I deploy out to a company that they are wanting to switch to end user installs. Becasue of that I need to hide the cd key and the admin password. What I thought is to dynamically build a script that the boot.wim would create a VBS file that would set the CD key and password parameters\variables. What I want to do is then pass them to my script that builds the sysprep.inf file dynamically.

So my question is how do I set values in a vbs and then call that vbs to pass parameters?

The first part is easy I believe:

ProdID = "1234-5678-abcd-efgh-ijkl"
AdminPassWord = "Password"

Except when I call this from my other script the values don't get set.

objWShell.Run "x:\settingVariables.vbs",0, True

'MsgBox ProdID' is blank

So what am I doing wrong?

Thanks for your help,
Randy


How to remove advertisement from MSFN

#2
Fredledingue

Fredledingue

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,267 posts
  • Joined 10-February 05
  • OS:98SE
  • Country: Country Flag
Sent params simply:
WshShell.Run "temp.vbs Text1 Text2 Text3", 1, True

Params containing white spaces
WshShell.Run "temp.vbs ""Mon Text 1"" ""Mon Text 2"" ""Mon Text 3""", 1, True

Named params:
WshShell.Run "temp.vbs /paramA:Text1 /paramB:Text2 /paramC:Text3", 1, True

Collect parameters aka arguments:
If only one:
Arg = WScript.Arguments(0)

If sevral:
Set Args = Wscript.Arguments
	For Each a in Args
	Arg=a
	Next

Taking named arguments
Set NamedArgs = Wscript.Arguments.Named
A = NamedArgs("ParamA")
B = NamedArgs("ParamB")
C = NamedArgs("ParamC")

Taking named and unamed arguments:
Set NamedArgs = Wscript.Arguments.Named
Set UnNamedArgs = Wscript.Arguments.Unnamed
A = NamedArgs("ParamA")
B = NamedArgs("ParamB")
C = NamedArgs("ParamC")
MyVar0 = UnNamedArgs(0)
MyVar1 = UnNamedArgs(1)
MyVar2 = UnNamedArgs(2)

HTASoft.com

superchargedwindows9xig1.png
Still Using W98SE+++ ...Daily.

#3
randalldale

randalldale

    Member

  • Member
  • PipPip
  • 115 posts
  • Joined 16-November 04
I'm using HTA files and wscript will not run in an HTA file.

Plus I'm not sure about the temp.vbs is this creating it or is it already created? It's kind of confusing to a noobe...

#4
Fredledingue

Fredledingue

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,267 posts
  • Joined 10-February 05
  • OS:98SE
  • Country: Country Flag
No, no, "temp.vbs" is an example and it represents your vbscript file.

The code to capture the parameter in hta is the following:
Here "testcmdl" is also an example, you can name the way you want, just without white space.
"testcmdl.commandLine" will return the entire command line used to launch the hta (including the param), so you will have to crop the text from the command line that you need.


<HEAD>
<HTA:APPLICATION ID="testcmdl">
<script LANGUAGE="VBScript">

Sub window_onLoad()
MyParam = testcmdl.commandLine
End Sub

</SCRIPT>
</HEAD>

HTASoft.com

superchargedwindows9xig1.png
Still Using W98SE+++ ...Daily.

#5
randalldale

randalldale

    Member

  • Member
  • PipPip
  • 115 posts
  • Joined 16-November 04
Fredledingue, I really appreciate your help but I still do not understand how I'm calling a vbScript and using the paramters in my HTA file.

you are saying

Sub window_onLoad()
MyParam = z:\MYvbScript.vbs.commanline
End Sub

I get 'Error: Expected Statement'

Here is what I'm trying to do, I have a vbScript that sets the parameter:

Dim ProdID, AdminPassword
ProdID = "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx"
AdminPassword = "Password"

This is saved as settingvariables.vbs ... very simple. I have that file in my boot structure under the BOOT.WIM file.

What I need to do is some how call that file and the parameters be usable in my HTA file.

I have tried
Sub window_onLoad()
Set objWShell = CreateObject("WScript.Shell")
objWShell.Run("x:\settingvariables.vbs"),0,True
End Sub
MsgBox ProdID

But the paramters do not get passed and are blank.

Thanks again for your help,
Randy

#6
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,430 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
I am going assume this
1:\ You have a vbs file that looks like this

Dim ProdID, AdminPassword
ProdID = "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx"
AdminPassword = "Password"


I am going assume this
2:\ That you want the hta to get the ID and PW from the hta, then try this

<HTA:APPLICATION ID='Install_MS'
  Scroll='No'			 
  SCROLLFLAT ='No'		
  SingleInstance='Yes'
  SysMenu='Yes'
  MaximizeButton='No'
  MinimizeButton='Yes'	 
  Border='Thin'
  BORDERSTYLE ='complex'  
  INNERBORDER ='Yes'
  Caption='Yes'  
  WindowState='Normal'
  APPLICATIONNAME='InstallMS' 
  Icon='%SystemRoot%\explorer.exe'>
 <STYLE Type='text/css'>
  Body
   {
	Font-Size:9.95pt;
	Font-Weight:Bold;
	Font-Family:segoeui,helvetica,verdana,arial;
	Color:#001142;
	BackGround-Color:Transparent;
	Filter:progid:DXImageTransform.Microsoft.Gradient
	(StartColorStr='#ece6e0',EndColorStr='#c0bab4');
	Margin-Top:2;
	Margin-Bottom:2;
	Margin-Left:2;
	Margin-Right:2;
	Padding-Top:2;
	Padding-Bottom:2;
	Padding-Left:2;
	Padding-Right:2;
	Text-Align:Left;
	Vertical-Align:Top;
	Border-Top:2px Solid #cbc7c3;
	Border-Bottom:3px Solid #a6a29e;
	Border-Left:2px Solid #bcb8b4;
	Border-Right:3px Solid #b2aeaa;
   }
 </STYLE> 
 <script Language="VBScript">
  Dim Act :Set Act = CreateObject("Wscript.Shell")
  Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
  Dim Vbs :Vbs = Act.CurrentDirectory & "\MYvbScript.vbs"
  window.resizeTo 475,271
  Function Window_onLoad()
   CheckForFile()
  End Function
  Function CheckForFile()
  If Fso.FileExists(Vbs) Then 
   Txt1.innerHTML = "Confirm"
	Dim Ts, Z1, Z2
	Set Ts = Fso.OpenTextFile(vbs,1)
	Do Until Ts.AtEndOfStream
	 Z1 = Ts.Readline
	 If Instr(Z1,"ProdID =") Or Instr(Z1,"AdminPassword =") Then
	  Z2 = Z2 & Z1 & "<BR>"
	 End If 
	Loop
	Txt1.innerHTML = "Confirm : " & Vbs & "<BR>" & Z2
  Else
   Txt1.innerHTML = "Missing"
  End If 
  End Function
 </SCRIPT>
<BODY>
 <TABLE Align='Left'><DIV ID='Txt1'> </DIV></TABLE>
</BODY>




GunSmokingMan



#7
randalldale

randalldale

    Member

  • Member
  • PipPip
  • 115 posts
  • Joined 16-November 04
Ok,

I figured it out...

Instead of creating the vbScript file I just needed to create a text file and read the lines on it into variables/arguments.

Const ForReading = 1
Set Fso = CreateObject("Scripting.FileSystemObject")
Set objFile = FSO.OpenTextFile("x:\settingVariables.txt", ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Execute strLine
Loop

objFile.Close

MsgBox ProdID
MsgBox AdminPassWord

Contents of the settingVariables.txt:

ProdID = "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx"
AdminPassWord = "Password"

You can now use it to hide important things like the CD ket and admin password inside your boot structure. I hope this helps someone besides me out...

Thanks again guys...

#8
Fredledingue

Fredledingue

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,267 posts
  • Joined 10-February 05
  • OS:98SE
  • Country: Country Flag
Yes, of course.

Instead of a loop you can type:

Execute ObjFile.ReadAll

Be careful to respect vbs syntax in the text file.

HTASoft.com

superchargedwindows9xig1.png
Still Using W98SE+++ ...Daily.

#9
Scr1ptW1zard

Scr1ptW1zard

    Junior

  • Member
  • Pip
  • 67 posts
  • Joined 05-July 07
Just include the file into your hta.


Place this above any other <script> tags:
<script Language=vbscript src="./yourfile.vbs"></script>

yourfile.vbs will have these line contained within:

Dim ProdID, AdminPassword
ProdID = "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx"
AdminPassword = "Password"

That's it.
--== Scr1ptW1zard ==--

#10
Fredledingue

Fredledingue

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,267 posts
  • Joined 10-February 05
  • OS:98SE
  • Country: Country Flag
Scr1ptW1zard,
I don't know if you can add a second script in vbscript inside the hta if you do that.

HTASoft.com

superchargedwindows9xig1.png
Still Using W98SE+++ ...Daily.

#11
Scr1ptW1zard

Scr1ptW1zard

    Junior

  • Member
  • Pip
  • 67 posts
  • Joined 05-July 07
Fredledingue,

I have several .hta's that I do this with. I have common script files that contain frequently used functions and subroutines. If I edit any of these common script files, my .hta's automatically have the update included. I find it very useful. Give it a try.

Here is my actual include statements for one of my HTA's:
<script Language=javascript src="./js/variables.js"></script>
<script Language=javascript src="./js/functions.js"></script>
<script language=javascript>
	window.onbeforeunload=preUnload;
</script>
<script Language=vbscript src="./vbs/objects.vbs"></script>
<script Language=vbscript src="./vbs/constants.vbs"></script>
<script Language=vbscript src="./vbs/subroutines.vbs"></script>
<script Language=vbscript src="./vbs/functions.vbs"></script>

--== Scr1ptW1zard ==--

#12
Fredledingue

Fredledingue

    MSFN Expert

  • Member
  • PipPipPipPipPipPip
  • 1,267 posts
  • Joined 10-February 05
  • OS:98SE
  • Country: Country Flag
Great! I didn't know it was pssible.
I seldom use the same functions from one script to another but it's useful to know.

What does this mean:
window.onbeforeunload=preUnload;

?

HTASoft.com

superchargedwindows9xig1.png
Still Using W98SE+++ ...Daily.

#13
cluberti

cluberti

    Gustatus similis pullus

  • Supervisor
  • 11,253 posts
  • Joined 09-September 01
  • OS:Windows 8.1 x64
  • Country: Country Flag

window.onbeforeunload=preUnload;

He's got a function called "preUnload" that he wants to fire on the page unload event. JScript sets an event handler for the window unload event, and executes the preUnload function somewhere in his code when the page unload event is raised.
MCTS Windows Internals, MCITP Server 2008 EA, MCTS MDT/BDD, MCSE/MCSA Server 2003, Server 2012, Windows 8
--------------------
Please read the rules before posting!
Please consider donating to MSFN to keep it up and running!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users