Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


changing drive with cmd

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> changing drive with cmd
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 changing drive with cmd - 8/19/2005 4:02:15 AM   
  jsou

 

Posts: 24
Score: 0
Joined: 7/22/2005
Status: offline
hey all,
i'm having a probelm i want a script to run from a cd-rom drive, so when i manually kick off the script theres code in there to place a call to the script in the windows run key so that after an automatic reboot the run key will point to the script file on the cd-rom drive and it should launch, but i haven't been able to.
I've tried just placing the path to the script in the run key such as:
strMyDrive (which is determined to be like D:\) & "test.vbs"
That didn't work so I tried using the cmd line and run it, but it starts off on the wrong drive and won't run:
"cmd /c wscript.exe " & strMyDrive & "test.vbs"
I'm looking for a way to change the drive of the command line so I can run it or if you know of another way I'd appreciate it.  Thanks.
 
 
Post #: 1
 
 RE: changing drive with cmd - 8/19/2005 4:33:46 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
I'm not sure I'm following you on this..
You have a VBScript that creates a registry key so that on reboot it kicks off another VBScript that resides on your CD-Rom drive?

If you're wanting a script to launch a script off of your CD, then you should be able to use this:

strDrive = "CDRom drive letter"

Set oShell = CreateObject("Wscript.Shell")
oShell.Run strDrive & "\myScript.vbs",0,True

(in reply to jsou)
 
 
Post #: 2
 
 RE: changing drive with cmd - 8/19/2005 4:56:55 AM   
  jsou

 

Posts: 24
Score: 0
Joined: 7/22/2005
Status: offline
well see after the reboot I put a call in the Run key of windows in the registry so that it will launch the script file in the CD-Rom.  Basically I need a way to run the script automatically off the reboot.

(in reply to jsou)
 
 
Post #: 3
 
 RE: changing drive with cmd - 8/19/2005 5:01:01 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Quick question, what are you using to get the letter of the CD?
Also,  just to add to what Country73 said,  Most times when you use WMI/vbscript to return a drive letter you will only get something like this: X:  there is no \ at the end, so you will need to add it.

ex.
On Error Resume Next

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_CDROMDrive")
For Each objItem in colItems
    msg = msg & "before: " & objItem.Drive & vbcr & "After:  " & objItem.Drive & "\" & vbcr
Next
msgbox msg

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to Country73)
 
 
Post #: 4
 
 RE: changing drive with cmd - 8/19/2005 5:09:56 AM   
  jsou

 

Posts: 24
Score: 0
Joined: 7/22/2005
Status: offline
well because i'll be manually starting off the script from the cd i just use:
the Wscript.ScriptFullName and just take the first three characters which would be the drive path with "\" already attached to it.

(in reply to jsou)
 
 
Post #: 5
 
 RE: changing drive with cmd - 8/19/2005 6:04:46 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
What's the exact entry you have in your registry?

I messed around with mine a little bit and was able to get my script to run from floppy and CD.

When you are retrieving the information for your CD drive, what script is doing that? Does that reside in your Temp directory?

My registry entry:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce    Name: myScript    Type: REG_SZ    Data: D:\myEcho.vbs

D:\ = my CD Drive
This script just launches a msgbox "Hello!"

(in reply to jsou)
 
 
Post #: 6
 
 RE: changing drive with cmd - 8/19/2005 8:12:19 AM   
  jsou

 

Posts: 24
Score: 0
Joined: 7/22/2005
Status: offline
so basically the script i run i have it run from the cd-rom itself.
that way when it looks for the current drive its on it will be the drive of the cd-rom
then i tag the registry HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\ with
strMyDrive & "\test.vbs"
so it will look like in the registry:
D:\test.vbs

Now through all my testing after reboots it never seems to run the script.  Is there another way of doing this?
Thanks for all your help so far.

(in reply to Country73)
 
 
Post #: 7
 
 RE: changing drive with cmd - 8/22/2005 1:03:46 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
Sorry I didn't get a chance to reply back this weekend; flag football for the little ones is just starting up!

OK, I just tested this again and this should work out for you.

'----------First Script (creates the registry key used for after reboot)---------
'Run_Once_Reg.vbs
'------------------------
Set oFS = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
SLOCAL = oFS.GetAbsolutePathName(".")
WshShell.RegWrite "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce\Test", SLOCAL & "\myEcho.vbs", "REG_SZ"

'----------Second Script (Just a msgbox to show the registry key took)------------
'myEcho.vbs
'--------------
wscript.echo "Hello!"


Let us know if that works out for you or not.

(in reply to jsou)
 
 
Post #: 8
 
 RE: changing drive with cmd - 8/22/2005 2:32:47 AM   
  jsou

 

Posts: 24
Score: 0
Joined: 7/22/2005
Status: offline
I was working on this late Friday night, I'm thinking the call to the script file is working, but I'm wondering if theres some delay time in executing the script from the CD-Rom?  Does WScript not got initialized?  I'm not sure why but when I take my same call to the script file in the Run key and place it in Start -> Run then the script will execute.  Does W2K not allow for scripts to be run if its found in the Run Key?  I've tried everything to putting the Path of the script file, calling wscript.exe before the path, and even using the command window to try and launch it, all with no success.               

(in reply to Country73)
 
 
Post #: 9
 
 RE: changing drive with cmd - 8/22/2005 2:53:25 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
Try rulling the CD-Rom out of it.
If you create a basic script at "C:\Temp\myscript.vbs" and then create the registry key to point to it, does the script run that way?

It may take a little longer for the script to start when running from CD. I ran it on my machine and it only took a few seconds, but as soon as I logged in I could hear the CD Drive start up.

(in reply to jsou)
 
 
Post #: 10
 
 RE: changing drive with cmd - 8/22/2005 3:10:13 AM   
  jsou

 

Posts: 24
Score: 0
Joined: 7/22/2005
Status: offline
yes running a script from the local hard drive works like a charm.  My project is to get the script to run from the CD-Rom drive however.

(in reply to Country73)
 
 
Post #: 11
 
 RE: changing drive with cmd - 8/22/2005 3:38:23 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
Yeah, I was just curious.

It seems to be running from my machine with no problem, so I don't know what the issue might be...

(in reply to jsou)
 
 
Post #: 12
 
 RE: changing drive with cmd - 8/22/2005 4:02:54 AM   
  jsou

 

Posts: 24
Score: 0
Joined: 7/22/2005
Status: offline
Here's some more details as to what I'm trying to accomplish, I'm starting the script off using my account, however within my script i create a new local admin account and password that when windows restarts it will automatically auto login into the newly created account from which there it still has the path in the HKLM...Run path to the CD-Rom where the script is to be ran from, however it doesn't run, but when I go back to my own account the script will launch from the CD-Rom.  Any ideas as to why it works on my account and not on the newly created account?  Any suggestions on how I would get this to work?  Thanks for your help this far.

(in reply to Country73)
 
 
Post #: 13
 
 RE: changing drive with cmd - 8/22/2005 4:15:51 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
I don't know what all you have going on with that machine, so I'm just trying to put the peices together in my head.
You create a new account, reboot machine, auto logon with new account, script never runs.

Are there any other applications launching at login?
When the machine is logged into with the new account, does it have access to the CD Drive? Can you manually go in and launch the script while that account is logged into the machine?

(in reply to jsou)
 
 
Post #: 14
 
 RE: changing drive with cmd - 8/22/2005 4:29:21 AM   
  jsou

 

Posts: 24
Score: 0
Joined: 7/22/2005
Status: offline
sorry its so confusing...
yes you are correct...
launch script (using my account)...that script creates a new local admin account...reboot machine...auto logon with new account...run key in place to launch script from cd-rom.

no other applications are running.
the new account does have access to the cd-rom drive and it's the same letter.  I can manually go in and launch the script from the new account.

If I just log out and log back into my own account, since the Run Key is still in place it launches the script from the CD-Rom Drive and continues on.

(in reply to Country73)
 
 
Post #: 15
 
 RE: changing drive with cmd - 8/22/2005 5:26:20 AM   
  Country73


Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
I really don't think the registry key is the problem, but the script won't launch (from that account) unless you manually launch it from the CD and your regular account will launch the script from the registry key...

Be sure this script is ran from your CD since one variable is created by where the first script is ran from. 
 
Probably a million different ways to write this, but here's one way.
Change / modify what's in RED for your purpose.
 
Set oFS = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
SLOCAL = oFS.GetAbsolutePathName(".")
          '=====================
          'Grabs the full path to current script
          '=====================
SSTART = "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\"
          '====================
          'Location to create startup script
          '====================

'=========================================
'Create the startup script
'=========================================
Set myFile = oFS.OpenTextFile(SSTART & "kickOff.vbs",8,True)
   myFile.WriteLine "Set oFS = CreateObject(" & chr(34) & "Scripting.FileSystemObject" & chr(34) & ")"
   myFile.WriteLine "Set WshShell = Wscript.CreateObject(" & chr(34) & "WScript.Shell" & chr(34) & ")"
   myFile.WriteLine "WshShell.Run chr(34) & " & chr(34) & SLOCAL & "\myEcho.vbs" & chr(34) & " & chr(34)"
   myFile.WriteLine "myFile = oFS.GetAbsolutePathName(" & chr(34) & "." & chr(34) & ")"
   myFile.WriteLine "oFS.DeleteFile myFile & " & chr(34) & "\kickOff.vbs" & chr(34)
   myFile.Close
'=========================================================
'The startup script will delete itself once it is launched
'=========================================================
wscript.echo "Startup script created"

(in reply to jsou)
 
 
Post #: 16
 
 
 
  

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 >> changing drive with cmd Page: [1]
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