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
 
you could use something like make sure you create a .vbs (VBScript) file instead of a .bat file
Code:
If msgbox("Change to backup system?", 0, "Are you sure?") = vbok Then
    do your unmapping/mapping here
End If

hope it helps
 
Sorry that should be

Code:
If msgbox("Change to backup system?", [b]1[/b], "Are you sure?") = vbok Then
    do your unmapping/mapping here
End If
 
Ok here's exactly what I need...
I have two servers. Primary is called GNMSRV. The backup is called GNMSRV-BK.
For the Primary server, the script is simple. It will simply unmap the L drive (if it exists) and re-map it (or map it if it didn't exist).
For the backup, it is a little more complicated. I would like it to pop up with a prompt.
"You are about to connect to the Backup Server. Type 'Y' to continue. If they do hit Y, it maps the drive to \\GNMSRV-BK\L as thier L drive. If they hit any other key but Y, the script closes and nothing is done.
I am pretty sure this is simple, but I haven't a clue how to do it. Can someone please show me exactly what to write here??? I need this working today (for Monday)...
-P
 
Code:
If msgbox("Do you want to connect to the Backup Server (GNMSRV-BK)?", vbyesno, "Connect?") = vbyes Then
    do your drive mapping for the backup server here
End If

When the user double-clicks the .vbs file they will be prompted with the text above with two options, Yes and No. If the user clicks 'Yes' that he/she wants to connect to the backup then the backup system will be mapped. If the user clicks 'No' nothing will happen
 
When testing that, this is what I get:

Script: C:\Documents and Settings\Administrator\backup.vbs
Line: 2
Char 5
Error: Expected Statement
Code: 800A0400
Source: Microsoft VBScript compilation error


any ideas?
this is what I have:

If msgbox("Do you want to connect to the Backup Server (GNMSRV-BK)?", vbyesno, "Connect?") = vbyes Then
\\gnmsrv-bk\l
End If
 
Did you look at the link that was provided above? There is a whole section there about getting user input.

[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]
 
Yes but honestly, I have never done this before :(
I have no idea what I am even reading. My boss dumped this in my lap and it has to be done by Monday...
-P
 
...at this point, I'd be willing to pay someone to write it for me...lol
-Pete
 
peteygnyc,

this should do it for you:
Code:
 msgbox("Do you want to connect to the Backup Server (GNMSRV-BK)?", vbyesno, "Connect?") = vbyes Then
    Set objNetwork = CreateObject("WScript.Network")
	objNetwork.MapNetworkDrive "L:", "\\GNMSRV-BK"
End If
hth
regards,
longhair
 
longhair,

I entered it exactly as you typed it and I am now getting:

Script: C:\Documents and Settings\Administrator\backup.vbs
Line: 1
Char 102
Error: Expected end of Statement
Code: 800A0401
Source: Microsoft VBScript compilation error

Any ideas?
 
peteygnyc,

works fine here. did you copy & paste out of the code box?
regards,
longhair
 
yes, exactly the way you had it...weird..
OK..Im gonna play with this and see if I could get it to work...thanks again man..

-Pete
 
could it be a different version or something? Im trying it on both win 2k and win xp boxes..
-P
 
peteygnyc,

sorry forgot the 'if':
Code:
If msgbox("Do you want to connect to the Backup Server (GNMSRV-BK)?", vbyesno, "Connect?") = vbyes Then
    Set objNetwork = CreateObject("WScript.Network")
	objNetwork.MapNetworkDrive "K:", "\\dataserver\ddrive"
End If
try it now.
regards,
longhair
 
peteygnyc,

obviously change the drive letter & server name.

regards,
longhair
 
Hey longhair...
That worked..you are the man.
However, because the L drive had previously been mapped, I got this message:

Script: C:\Documents and Settings\Administrator\backup.vbs
Line: 3
Char 5
Error: An attempt was made to remember a device that had previously been remembered.
Code: 800704B2
Source: WSHNetwork.MapNetworkDrive

Is there any way to delete the share if it is already mapped? The problem is, both servers are similar (L drive) and both map AS the L drive. We need to be able to have users switch to the other if one is down.

Thanks again for all your help!
-Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top