Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input Box to resolve variable name

Status
Not open for further replies.

goldstem

Technical User
May 21, 2009
10
Hello everyone,

The extent of my VB Script knowledge is enough to butcher other people(s') scripts for my own use, and they're probably inefficient, but have worked.

Scenario -
300 workstations need a perconfigured ini file
*Here's the catch*
Each workstation has it's own INI file.

This is what I have as far as trying to get a script to work -

Dim objShell, strComputer, strInput
Dim objFSO

Do
strComputer = (InputBox(" ComputerName to Copy File", "Computer Name"))
If strComputer <> "" Then
strInput = True
End if

Set oShell = CreateObject( "WScript.Shell" )

strcomputer=oShell.ExpandEnvironmentStrings("%Computername%")

set objFSO=CreateObject("Scripting.FileSystemObject")
objFSO.CopyFolder "\\hq-filestore\apps\storeforward\_branches\workstations\%computername%\*", "\\%computername%\C$\Program Files\PowerTerm\"
objFSO.CopyFile "\\hq-filestore\apps\storeforward\_branches\workstations\%computername%\ptcomm.ini", "\\%computername%\C$\Program Files\PowerTerm\"
End If

Wscript.Quit


The goal and function of this script is to have an input box to open and the user types in the workstation name to resolve the variable %computername%.

I've created several workstation folders so all the names will correspond with eachother.

And please, no suggestions of 3rd party apps, we have reason why we're going the script route.

Thank you in advance!
 
A starting point:
Code:
Set objFSO=CreateObject("Scripting.FileSystemObject")
strComputer = InputBox(" ComputerName to Copy File", "Computer Name")
If strComputer <> "" Then
  objFSO.CopyFolder "\\hq-filestore\apps\storeforward\_branches\workstations\" & strComputer & "\*", "\\" & strComputer & "\C$\Program Files\PowerTerm\"
  objFSO.CopyFile "\\hq-filestore\apps\storeforward\_branches\workstations\" & strComputer & "\ptcomm.ini", "\\" & strComputer & "\C$\Program Files\PowerTerm\"
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
It all looks good, but then the script tries to pull an incorrect path.
 
Why do you even use an inputbox to get the computername?

Code:
Set objFSO=CreateObject("Scripting.FileSystemObject")
SetWSHNetowrk = CreateObject("Wscript.Network")
strComputer = WSHNetwork.Computername
  objFSO.CopyFolder "\\hq-filestore\apps\storeforward\_branches\workstations\" & strComputer, "\\" & strComputer & "\C$\Program Files\PowerTerm\"
  objFSO.CopyFile "\\hq-filestore\apps\storeforward\_branches\workstations\" & strComputer & "\ptcomm.ini", "\\" & strComputer & "\C$\Program Files\PowerTerm\"

Note the exclusion of \* from the copyfolder line, it should not be needed.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Not all workstations will be receiving these files. It's for a rollout project we're doing.
 
By combining both versions of the script, it worked!

Set objFSO=CreateObject("Scripting.FileSystemObject")
strComputer = InputBox(" ComputerName to Copy File", "Computer Name")
If strComputer <> "" Then
objFSO.CopyFolder "\\hq-filestore\apps\storeforward\_branches\workstations\" & strComputer, "\\" & strComputer &

"\C$\Program Files\PowerTerm\"
objFSO.CopyFile "\\hq-filestore\apps\storeforward\_branches\workstations\" & strComputer & "\ptcomm.ini", "\\" &

strComputer & "\C$\Program Files\PowerTerm\"
End If
 
I need to ask one last favor...

Success/Failure message.
 
You don't have to make it a login script to automatically find the computername, why please explain why that idea was rejected?

If however you did want to set as a login script, you could do so and check for the existence of that program folder first and then run this.

Code:
Set objFSO=CreateObject("Scripting.FileSystemObject")
SetWSHNetowrk = CreateObject("Wscript.Network")
strComputer = WSHNetwork.Computername
On Error Resume Next
If objFSO.FolderExists("\\" & strComputer & "\C$\Program Files\PowerTerm\") Then
     objFSO.CopyFolder "\\hq-filestore\apps\storeforward\_branches\workstations\" & strComputer, "\\" & strComputer & "\C$\Program Files\PowerTerm\"
     objFSO.CopyFile "\\hq-filestore\apps\storeforward\_branches\workstations\" & strComputer & "\ptcomm.ini", "\\" & strComputer & "\C$\Program Files\PowerTerm\"
End If
If Err.Code = 0 Then
   MsgBox "Update completed successfully."
Else
   MsgBox "Error copying files.  Contact Support."
End If

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
We have a series of thinclients.
We have Non-embedded workstations and embedded XP (Wyse) terminals.
The non-embedded have nothing installed locally on those machines, but our Wyse machines launch an embedded XP OS which have individual configurations. We'll need to update certain wyse machines about 2 a year, but we cannot do these updates in one shot (long infrastructure story), so it'll be done in waves.
 
Thanks for that explanation. I think the code I last posted should do it for you. If you run it on the non-embedded systems nothing will be copied. Run it on the systems that have the software installed and you will get the files copied.

If you execute on a system that has the embedded OS but doesn't have the software, again nothing will happen.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
I tried running your script Mark (and I do appreciate all the help you have given me), but I receive an error-

Object doesn't support this property or method: 'SetWSHNetwork'
 
Sorry that is a typo Should be
Code:
Set WSHNetwork
Too early in the AM I guess for me.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Thanks again Mark, but it did not prompt for the workstation name, and it seems to always be a successful result.

I need to ONLY manually enter the workstation names.
 
It would not prompt, it dynamically grabs that information. I still don't follow why you want to force the user to get information that can be grabbed dynamically. Put in whatever checks are needed to ensure the script only executes on the machines you want and be done with it.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
This is a central script, not a logon script. The only people running this script (manually) is the IT staff.
 
deadhorse.gif


That is fine, why would the IT staff not want to just double click and be done with it?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
The workstations are spread out around the region, and not being done all at once.

I appreciate your thought of having this automated with a single click, but with our infrastructure, we need to be very controlled with this rollout.
 
We must have a miscommunication between us. I don't see the difference between a tech manually running the script on a desired PC and having him enter the machine name VS having a tech manually running the script and having that script dynamically grab the machine name that the tech would enter. In either case you exercise the same control. The latter scenario is just easier for the tech, and automation is the whole reason to script.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top