Reference text with vbs

Discussion in 'Software' started by danjferguson, Jan 11, 2007.

  1. danjferguson

    danjferguson Private E-2

    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.
     
  2. Mada_Milty

    Mada_Milty MajorGeek

    Well, I would leave your batch files as is, and create a VBScript layer that passes the computer name to the batch file.

    Code:
    option explicit [COLOR="Lime"]' This command forces explicit variable declaration
    [/COLOR]
    dim o_net, o_shell [COLOR="Lime"]' Creates two variables which I intend to use as object[/COLOR]
    dim v_name [COLOR="Lime"]' Creates a variable I will use as a string
    [/COLOR]
    const c_batch = "[I]fullPathToBatchFile[/I]\admin.bat"[COLOR="Lime"] ' Creates a constant string value storing the path to and name of the batch file[/COLOR]
    
    set o_net = createobject ("WScript.Network") [COLOR="Lime"]' This creates a network object, and sets o_net equal to it[/COLOR]
    set o_shell = createobject ("WScript.Shell") [COLOR="Lime"]' This creates a Windows shell object, and sets o_shell equal to it[/COLOR]
    
    v_name = "\\" & o_net.computername [COLOR="Lime"]' This sets v_name equal to "\\[I]computername[/I]"
    [/COLOR]
    o_shell.run (c_batch & " " & v_name, 5, false) [COLOR="Lime"]' 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[/COLOR]
    
    set o_net = nothing [COLOR="Lime"]' This releases the o_net variable[/COLOR]
    set o_shell = nothing [COLOR="Lime"]' This releases the o_shell variable[/COLOR]
    WScript.Quit() [COLOR="Lime"]' This terminates script execution[/COLOR]
    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.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds