Photo Gallery Member List Search Calendars FAQ Ticket List Log Out



renew IP address in login script

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,25435
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> renew IP address in login script
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 renew IP address in login script - 9/1/2005 3:37:26 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
Hi,

does anyone have a script to release and renew the ip address?

we have a new dhcp server and all workstation needs to release and renew before it expires.

i'm trying to avoid going to 500 plus computers.


 
 
Post #: 1
 
 RE: renew IP address in login script - 9/1/2005 3:57:14 AM   
  thantos_kalev2001


Posts: 26
Score: 0
Joined: 8/31/2005
Status: offline
You could call a command line in a vbscript and just use ipconfig/release and ipconfig/renew.

For example:

Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.run("%comspec% /k ipconfig /release")
objShell.run("%comspec% /k ipconfig /renew")


Thantos Kalev

(in reply to kracksmith)
 
 
Post #: 2
 
 RE: renew IP address in login script - 9/1/2005 4:19:59 AM   
  mbouchard


Posts: 1986
Score: 18
Joined: 5/15/2003
From: USA
Status: offline
One thing to keep in mind, as soon as you release you will lose your connection to your netlogon share and there is a strong possibility that the script will not work properly.  What I would recommend is this, create a script and save it in your netlogon share.  This script would essentally do what thantos says below.  Release the IP, renew the IP, then it would check for the login script, you can have a loop here that would check every few seconds.  And once it can see the login script, it 1) writes a log file that is used by the login script, this would be used to prevent it from copying and running the ipconfig renew script again, 2) Runs the login script, and 3) deletes itself.

Now, in your login script do something like this:

If Tagfile doesn't exist Then
Copy ip renew script to PC
run ipscript
quit
End If

Then when your sure all PC's have been renewed, you can change the code to delete the tag file if it does exist.

One note, do not call the 2nd script ipconfig.vbs.  It will not work properly as it will try to run the ipconfig.exe.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to kracksmith)
 
 
Post #: 3
 
 RE: renew IP address in login script - 9/2/2005 2:52:36 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
Thanks for your assistance

Here is what i have so far. it will copy the "release & renew.bat file" from the server to their C directory but i can't get it to run.


also i need to delete this .bat file once it completes it's duties.



Option Explicit
Dim network, fso
Set network = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
WScript.Echo "Your IP Address will release and renew with this script"
fso.CopyFile "\\Prod2\N_Drive\Public\Prod2 Print Scripts\rapid.bat", "C:\"
'WshShell.Run "cmd /c rapid.bat"
quit

(in reply to mbouchard)
 
 
Post #: 4
 
 RE: renew IP address in login script - 9/2/2005 3:17:15 AM   
  thantos_kalev2001


Posts: 26
Score: 0
Joined: 8/31/2005
Status: offline
Try this code to get it to execute:

WshShell.run("%comspec% /c c:\rapid.bat")
 
And then this to delete the file locally:

fso.DeleteFile "c:\rapid.bat"
 
Cheers!
Thantos


(in reply to kracksmith)
 
 
Post #: 5
 
 RE: renew IP address in login script - 9/2/2005 3:30:32 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
it's not running the .bat file.

%comspec% means it suppose to go to windows/system32/cmd.exe right?  somehow it's not opening up a command prompt for the .bat to take into effect

am i leaving anything out of my script below?


Option Explicit
Dim network, fso
Set network = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
WScript.Echo "Your IP Address will release and renew with this script"
fso.CopyFile "\\Prod2\N_Drive\Public\Prod2 Print Scripts\rapid.bat", "C:\"
WshShell.run("%comspec% /c c:\rapid.bat")
fso.DeleteFile "c:\rapid.bat"
quit

(in reply to thantos_kalev2001)
 
 
Post #: 6
 
 RE: renew IP address in login script - 9/2/2005 3:38:35 AM   
  mbouchard


Posts: 1986
Score: 18
Joined: 5/15/2003
From: USA
Status: offline
Try telling it where the cmd.exe is.  Something like this.

If fso.FileExists("c:\windows\system32\cmd.exe") then
    WshShell.Run "c:\windows\system32\cmd.exe /C c:\rapid.bat"
ElseIf fso.FileExists("c:\winnt\system32\cmd.exe") then
    WshShell.Run "c:\winnt\system32\cmd.exe /C c:\rapid.bat"
Else
    Msgbox "Something is wrong"
End If

I am just wondering if comspec is not working as the environment variables are not set/configured/whatever.  Not sure of the timing.

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to kracksmith)
 
 
Post #: 7
 
 RE: renew IP address in login script - 9/2/2005 3:47:38 AM   
  thantos_kalev2001


Posts: 26
Score: 0
Joined: 8/31/2005
Status: offline
Here is what I used to get it to work:

Set network = WScript.CreateObject("WScript.Network")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")


WScript.Echo "Your IP Address will release and renew with this script"
fso.CopyFile "
\\networkpath", "C:\test\"
WshShell.run("%comspec% /k c:\test\batFileName.bat")

WScript.Sleep 2500
fso.DeleteFile "c:\test\batFileName.bat"

I am pretty sure that you dont need the OPTION EXPLICIT or QUIT.  I did not have luck getting it to copy the file to the local C drive, but it works if you copy it to a folder on the local drive, as I have shown in the above script. 
You might want to use what I have above, and just put in your server pah and .bat file name.

Thantos

(in reply to kracksmith)
 
 
Post #: 8
 
 RE: renew IP address in login script - 9/2/2005 3:50:40 AM   
  thantos_kalev2001


Posts: 26
Score: 0
Joined: 8/31/2005
Status: offline
Mbouchard is right about the comspec...I am running windows Xp, but you might have a different path to the command line.  Replacing %comspec% with cmd should work as well...I just used what works for me.

Sorry for the confusion!

Thantos

(in reply to thantos_kalev2001)
 
 
Post #: 9
 
 RE: renew IP address in login script - 9/2/2005 3:56:34 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
i don't think my scripts likes the "WshShell"

do i need to create an object for this or anything?

would this script just reconize "WshShell"?



(in reply to mbouchard)
 
 
Post #: 10
 
 RE: renew IP address in login script - 9/2/2005 3:56:36 AM   
  Country73


Posts: 746
Score: 10
Status: offline
You should also be able to use:

WshShell.run "cmd /c c:\test\batfileName.bat",0,True
fso.DeleteFile "c:\test\batfileName.bat"

Running it this way will hide the command window, wait for the batch file to complete before going to the next step. (which is deleteing the bat file)
That way you don't run into some machines "hanging" and the script trying to delete the bat file before completion.




< Message edited by Country73 -- 9/2/2005 3:58:00 AM >

(in reply to thantos_kalev2001)
 
 
Post #: 11
 
 RE: renew IP address in login script - 9/2/2005 4:36:15 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
ok, thanks to everyone!


here is my final working script:


Set network = WScript.CreateObject("WScript.Network")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
'WScript.Echo "Click OK to release & renew your IP address"
fso.CopyFile "\\Prod2\N_Drive\Public\Prod2 Print Scripts\rapid.bat", "C:\"
WshShell.run("%comspec% /k c:\rapid.bat")
WScript.Sleep 100000
fso.DeleteFile "c:\rapid.bat"


my rapid.bat


ipconfig /flushdns
gpupdate /force
ipconfig /release
ipconfig /renew
exit

(in reply to Country73)
 
 
Post #: 12
 
 RE: renew IP address in login script - 9/2/2005 8:08:48 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
i took country 73 suggestion which runs everything trully in the background

Here is my final script revised:


Set network = WScript.CreateObject("WScript.Network")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
fso.CopyFile "\\Prod2\N_Drive\Public\Prod2 Print Scripts\rapid.bat", "C:\"
WshShell.run "cmd /c c:\rapid.bat",0,True
WScript.Sleep 100000
fso.DeleteFile "c:\rapid.bat"


my rapid.bat

ipconfig /flushdns
gpupdate /force
ipconfig /release
ipconfig /renew
exit

(in reply to kracksmith)
 
 
Post #: 13
 
 RE: renew IP address in login script - 9/2/2005 9:14:39 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
Sorry guys.

This script doesn't run from the network. So if its is ran in the login script then it won't work. testing it locally works but there's no point.

everything works until it runs the "rapid.bat" which release the ip address and Bam! no connection. So basically I had to goto that workstation and "ipconfig renew".



I believe I need 2 vbs script.


1st script is to copy 2 files from network to local C drive (ip_renew.vbs & rapid.bat)   & we can name this 1st script = copy.vbs

then in this copy.vbs script to run ip_renew.vbs

ip_renew.vbs is a local script in C drive should run the rapid.bat,  wait awhile then delete 2 files in the C drive (ip_renew.vbs & rapid.bat)


This is what I have so far


copy.vbs:

Set network = WScript.CreateObject("WScript.Network")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
fso.CopyFile "\\Prod2\N_Drive\Public\Prod2 Print Scripts\rapid.bat", "C:\"
fso.CopyFile "\\Prod2\N_Drive\Public\Prod2 Print Scripts\ip_renew.vbs", "C:\"

(need the verbage to run the ip_renew.vbs in local C drive after the copying)



ip_renew.vbs:

Set network = WScript.CreateObject("WScript.Network")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.run "cmd /c c:\rapid.bat",0,True
WScript.Sleep 100000
fso.DeleteFile "c:\rapid.bat", "c:\ip_renew.vbs"



rapid.bat:

ipconfig /flushdns
gpupdate /force
ipconfig /release
ipconfig /renew
exit



or is there a easier way doing it with 1 script? I can't image there is since ipconfig /release will disconnect everything

< Message edited by kracksmith -- 9/2/2005 9:16:04 AM >

(in reply to kracksmith)
 
 
Post #: 14
 
 RE: renew IP address in login script - 9/6/2005 2:03:43 AM   
  thantos_kalev2001


Posts: 26
Score: 0
Joined: 8/31/2005
Status: offline
Have you tested your 2 script method?  This looks like it should work.

One caveat:  My script stalls when I run the gpupdate/force command--I am prompted on whether or not I want to reboot, and it hangs my script.  Maybe this is causing the problem with yours?   You might want to just use gpupdate rather than gpupdate/force .


Thantos

(in reply to kracksmith)
 
 
Post #: 15
 
 RE: renew IP address in login script - 9/6/2005 3:06:18 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
gpupdate /force works here.

if it doesn't in the future I'll use gpupdate.


my script still doesn't work as I need my 1st script to call or run my 2nd script. I don't have the verbage for this.


how do I run my 1st script then ask this 1st script to run another script?

(in reply to thantos_kalev2001)
 
 
Post #: 16
 
 RE: renew IP address in login script - 9/6/2005 11:01:56 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
Would this be the correct verbage which I'll put in my 1st script called "copy.vbs"?

I want my 1st script called "copy.vbs" to run another script called "ip_renew.vbs"

then this ip_renew.vbs will run the rapid.bat


objShell.Run "C:\ip_renew.vbs"



(in reply to kracksmith)
 
 
Post #: 17
 
 RE: renew IP address in login script - 9/7/2005 12:18:24 AM   
  thantos_kalev2001


Posts: 26
Score: 0
Joined: 8/31/2005
Status: offline
Yes, that will work.  Just make sure that you have that .vbs file in the C directory! 
:)

Thantos

(in reply to kracksmith)
 
 
Post #: 18
 
 RE: renew IP address in login script - 9/7/2005 1:24:01 AM   
  DiGiTAL.SkReAM


Posts: 1200
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Do you really need to have a ipconfig/renew statement?  Correct me if I am wrong, but if you do a ipconfig/release, and then reboot the workstation, will it not reach for a new IP via DHCP when it comes back on?
If you are running the scripts on Windows Xp Pro boxen, you shoudl be able to just do this:
(Lines in your login.bat)
if not exist c:\IPChangeDone.Markfile xcopy \\server\share\rapid.cmd c:\ /y
if exist c:\rapid.bat start %comspec% /c c:\rapid.cmd
:EOF

Then, your rapid.cmd file should contain:
ipconfig/release
echo. > c:\IPChangeDone.Markfile
shutdown -r -t 10 -c "Workstation rebooting to facilitate network maintenance.  Please Stand By" -f
:EOF

You would call the rapid.bat file from the login.bat as the very last thing that you do because as soona s you do, the network conenction would be lost.
As you can see from above, the order of events is:
1.) If the log file is not present, it means that the job has not run, so go ahead nad copy rapid.bat over to C:\
2.) if the rapid.bat file is present, run it.

Conversely, if you would rather just do everything from one line in your login.bat, without having to reboot, or run external files, etc... you can use this command as the last one in your login.bat file:

if not exist c:\IPChangeDone.Markfile ipconfig/release&&ipconfig/renew&&echo. > c:\IPChangeDone.Markfile&&shutdown -r -t 5 -f

That way, if it doesn't find the mark file, it will release and renew the IP address, create the mark file, and then reboot the workstationw ith a five second delay.

Hope this helps.


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to thantos_kalev2001)
 
 
Post #: 19
 
 RE: renew IP address in login script - 9/7/2005 7:57:52 AM   
  kracksmith

 

Posts: 198
Score: 0
Joined: 2/24/2005
From:
Status: offline
Ok, thanks for everyone’s input. Everything is perfect and I can sleep better now.
 
I found out that my 1st final script does work over the network. It just the .bat file doesn’t work over the network drive mappings when testing but does work over the network itself.
 
Both of these works if anyone needs it.
 
 
Script 1:
 
Set network = WScript.CreateObject("WScript.Network")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
fso.CopyFile "\\Prod2\N_Drive\Public\Prod2 Print Scripts\rapid.bat", "C:\"
WshShell.run "cmd /c c:\rapid.bat",0,True
WScript.Sleep 100000
fso.DeleteFile "c:\rapid.bat"
 
 
 
Script 2:
 
Copy.vbs
 
Set network = WScript.CreateObject("WScript.Network")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
Set WshShell = Wscript.CreateObject("Wscript.Shell")
fso.CopyFile "\\Prod2\N_Drive\Public\Prod2 Print Scripts\rapid.bat", "C:\"
fso.CopyFile "\\Prod2\N_Drive\Public\Prod2 Print Scripts\ip_renew.vbs", "C:\"
WshShell.Run "C:\ip_renew.vbs"
 
 
 
Ip_renew.vbs
 
Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
WshShell.run "cmd /c c:\rapid.bat",0,True
WScript.Sleep 100000
fso.DeleteFile "c:\rapid.bat"
fso.DeleteFile "c:\ip_renew.vbs"
 
 
 
rapid.bat
 
ipconfig /flushdns
gpupdate /force
ipconfig /release
ipconfig /renew
exit
 
 
 
 
DiGiTAL.SkReAM when I do a IPCONFIG /RELEASE & /RENEW i don’t need to restart my computer. I do need this statement because we configured DHCP to another server. So basically I need to release and renew every workstation otherwise all workstations IP will expire within a week.
 
Thanks for your input regarding markers. I need to implement it another time as I don’t have time to mess around with this script any more. For now hopefully everyone can logoff and log back on within 2 days. Then I’ll just take it off the login group policy.

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> renew IP address in login script Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts