PDA

View Full Version : Reference text with vbs


danjferguson
01-10-07, 23:14
A quick run down of what I'm trying to do:

I'm have batch files (named admin.bat and share.bat respectively)loaded that look like this:

runas /netonly /user:%1\admin "\\server\share\%1.msc"

and this:

runas /netonly /user:%1\admin "\\%1\share"

I used this to give inexperienced users access to certain remote computer drives and management consoles that I made up with mmc. I was typing out each computer name and creating new batch files for each computer on my network, but this is very time consuming, especially during equipment change outs with new computers/computer names. I already have a word document made up with a table of all the computers in my network, and I also have scripts made to export AD info to excell if I wanted to even automate that, but I am unable to insert the text of the computer name from the document to run right after the batch file so it runs in the command line like this on a computer with the computer name CPU1:

runas /netonly /user:cpu1\admin "\\server\share\cpu1.msc"

Is there anyway to get the CPU1 to follow the entry of admin.bat when the command line is opened? I have scoured the web for hours looking for something that would do it but it seems my situation is unique. No, I cannot give users access to the AD or give them local administrator accounts otherwise this would be easy. I also dont want to do this every time someone new needs access, when I can just give them a password that I have specified and they enter it when they click on the link to this batch file. Is there a VBS command I can use to accomplish this? I have some VBS experience, but not enough to tackle this one.

Mada_Milty
01-11-07, 07:00
Well, I would leave your batch files as is, and create a VBScript layer that passes the computer name to the batch file.

option explicit ' This command forces explicit variable declaration

dim o_net, o_shell ' Creates two variables which I intend to use as object
dim v_name ' Creates a variable I will use as a string

const c_batch = "fullPathToBatchFile\admin.bat" ' Creates a constant string value storing the path to and name of the batch file

set o_net = createobject ("WScript.Network") ' This creates a network object, and sets o_net equal to it
set o_shell = createobject ("WScript.Shell") ' This creates a Windows shell object, and sets o_shell equal to it

v_name = "\\" & o_net.computername ' This sets v_name equal to "\\computername"

o_shell.run (c_batch & " " & v_name, 5, false) ' This runs the batch file, passing the above name to it. The 5 means the cmd.exe window should be active and its normal size, the false means the vbscript will continue execution, rather than waiting for the batch to finish

set o_net = nothing ' This releases the o_net variable
set o_shell = nothing ' This releases the o_shell variable
WScript.Quit() ' This terminates script execution

I believe the above will do the trick for you. You can alter this so that it executes either script, it's just a matter of changing the path to reflect where you store the batch files, and which batch file you wish to run.