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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file question...

Status
Not open for further replies.

peteygnyc

IS-IT--Management
May 25, 2005
30
US
Hey everyone,
I was just wondering if there is a way to execute a batch file from a desktop which prompts the user to continue. I am pretty sure it is possible but I have no clue how to do it.
My situation is this: I have two severs running proprietary software. One is Primary, one is Backup. I would like to create a script which disconnects the Primary server and connects to the Backup. Before it does that, it prompts the user that they are "About to connect to the backup server, do you want to continue? Press Y to connect, and N to exit." If they continue, it disconnects the mapping to the Primary, and re-maps to the Backup.
How difficult is it to do? The drive mappings are cake, but its the IF/THEN question which I do not know the syntax for. Anyone here know?
Thanks.
-Pete
 
Another question...(sorry)
Does this work for executables as well?
For instance,

Say I have an application which requires switches in order to run. When the user clicks on this script, can it be configured to run the executable on the mapped network drive?
Ex:
\\gnmsrv\L\dad\das_app.exe gnmsrv-bk das 0

What I really want is the app to auto-run if the user clicks on it and says connect.

-Pete
 
peteygnyc,

to remove the drive:
Code:
DriveLetter1 = "L:"

Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

objNetwork.RemoveNetworkDrive DriveLetter1
just put before you map your new drive
as for running an .exe you will have to do a search for it. try "run program"+.vbs via google.
hth
regards,
longhair
 
Ok what if the drive does not exist for whatever reason? Is there an IF/THEN thing I could use?
Like If exist L: then net use L: /delete
END If

-P
 
Ok..I got them to map...the default login script maps them to \\gnmsrv\L as their L drive. Every user logs in and runs that script.
Now, I will be placing this vbscript icon on their desktops and giving them the option of switching. This works, deletes the old path to the L drive, maps the new path on the \\gnmsrv-bk server but they still have to open the L drive and run the exe file with the right switches.
I am beating my head against the wall trying to find info on how to do this. The command is:
\\gnmsrv\L\dad\das_app.exe gnmsrv-bk das 0

At this point, I just need to know how to incorporate this into the vbscript so that all the user has to do, is click CONNECT and it will open the application. I thought this would be a simple thing, but I am seeing now that it is turning into a nightmare :(


This is the vbscript that works for me thus far:

If msgbox("Do you want to connect to the Backup Server (GNMSRV-BK)?", vbyesno, "Connect?") = vbyes Then
DriveLetter1 = "L:"
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

objNetwork.RemoveNetworkDrive DriveLetter1
Set objNetwork = CreateObject("WScript.Network")
objNetwork.MapNetworkDrive "L:", "\\GNMSRV-BK\L"
End If
 
peteygnyc,
shouldn't really matter - no matter what if they want to use the backup server just delete and remap.
or did i read your question wrong?
regards,
longhair
 
longhair,

no you didnt read it wrong. The problem is, in the code, it tried to add the new drive map. only problem is, every user already had the L drive mapped to the primary server. We want to be able to have the users be able to switch to the backup server at any time in case there is a problem with the primary. This is a system in a hospital and is critial for the users to be able to work.
I managed (through googling) to get the script to remove the primary and switch to the backup, but the application they need to run requires switches made from either a command line, or within the shortcut which exists already on their desktops. As of right now, they double click the icon on their desktops to get into the app. This works fine now because the shortcut is pointing to the primary server. We need there to be a backup icon. We wanted to make this as simple and pain free as possible by creating an icon on users desktops (the vbscript) where they can switch on the fly.

-Pete
 
WHy don't you just modify the shortcut target when you switch them to the backup?


[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
peteygnyc,
ok - look at TomThumbKP's idea or do they have to be the same drive letter? i'm thinking along the lines of L = primary M = back up. if they need to use the back up, delete L, map M. let them have 2 icons for the app 1 is primary 1 is back up. if primary is not mapped they won't be able to use.
regards,
longhair
 
No, this has to be one or the other. I thought of just creating a local mapping of a different drive letter but they cannot even have the option of being on both servers at once. By deleting the driveshare, and then re-mapping the same drive letter to a different server, this eliminates that.
-P
 
Try the following, it might work
Code:
If msgbox("Do you want to connect to the Backup Server (GNMSRV-BK)?", vbyesno, "Connect?") = vbyes Then
    DriveLetter1 = "L:"
    Set objShell = CreateObject("WScript.Shell")
    Set objNetwork = CreateObject("WScript.Network")
    
    objNetwork.RemoveNetworkDrive DriveLetter1
    Set objNetwork = CreateObject("WScript.Network")
    objNetwork.MapNetworkDrive "L:", "\\GNMSRV-BK\L"

    [b]objShell.Run "\\gnmsrv\L\dad\das_app.exe gnmsrv-bk das 0"[/b]
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top