Can someone confirm this if possible.
script is below - read a text file contains all the reserve drives.
get a list of logical drive via WMIC into a text, regex out the name, : and just leave the letter as is in side the variable.
run through D-Z, find the next available drive
pass the avialble drive, reserve drive letter to the changeD subroutine in vbscript. which than change the reservedrive letter which if found and change it to the available drive letter.
I know what the problem is but cannot confirm if its system setup related or if its os related.
I am running windows 8, UAC is on.
There's 3 account on this PC which is hock to our workplace's network using group policy.
The account i m on is part of the Administrator group.
There's a user account call Administrator on this PC which is also administrator group.
Code: Select all
// COMPILE_OPTS|C:\temp\test.exe||CONSOLE=0|INCLUDES=1||RUNTIMES=1|BMPS=1
VBSTART
sub ChangeD (DriveL,ReserveName)
dim objWMIService
dim drvVol
set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
'type 5=cdrom,6Ram,4network,2removeable,3logical, remove from DriveType in (x,x,x,x) if you want to include them .
'this will look for all cdrom/ram,network and removeable disc only.
set drvVol=objWMIService.execquery("select * from Win32_Volume where (DriveType=5 or DriveType=4 or DriveType=2 or DriveType=6) and Name='" & ReserveName & ":\\'")
if drvVol.count=1 then
'should only be 1
for each vol in drvVol
vol.DriveLetter="" & cstr(DriveL) & ":"
vol.Put_
next
set objWMIService=nothing
set drvVol=nothing
else
msgbox "Found " & drvVol.count & " will not attempt!"
end if
end sub
VBEND
'for multiple drive reserve potential.!! - have not completely test with network drives etc.
readfile>%script_dir%\ReserveDrives.txt,reserveDrives
trim>reserveDrives,reserveDrives
Separate>reserveDrives,crlf,drives
let>j=0
repeat>j
add>j,1
let>reserveDrive=drives_%j%
if>reserveDrive<>
gosub>ProcessDriveChange
endif
Until>j=drives_count
goto>ENDProgram
'for Single drive reserv
//let>reserveDrive=E
//gosub>ProcessDriveChange
SRT>ProcessDriveChange
let>LOCALVAR=1
ife>%script_dir%\DriveName.txt
deletefile>%script_dir%\Drivename.txt
endif
runprogram>cmd.exe /c wmic logicaldisk get name > %script_dir%\DriveName.txt
wait>1
readfile>%script_dir%\DriveName.txt,discName
regex>:,discname,,m,n,1,,discname
regex>Name,discname,,m,n,1,,discname
'ascii values for drive letter A-65, Z=90
'find the next drive available not used.
'start at D to Z
let>k=67
repeat>k
add>k,1
VBEval>Chr(%k%),charVal
regex>%charVal%,discname,,m,n,0,
regex>%charVal%,reserveDrives,,o,p,0,
if>{(%n%=0) and (%p%=0)}
vbrun>ChangeD,%charVal%,%reserveDrive%
wait>2
let>k=90
endif
Until>k=90
End>ProcessDriveChange
//let>nextDrive=H:
//vbrun>changeD,%nextDrive%
Label>ENDProgram
/*ReserveDrives.txt
E
G
I
*/
The area where i m having a problem with is:
Code: Select all
runprogram>cmd.exe /c wmic logicaldisk get name > %script_dir%\drivename.txt
if i run this is command promp directly (wmic logicaldisk.. etc). the output gives me all the drives
if I open command prompt as Administrator (via right click run as administrator), and run the same command, i get all drive except 1 drive (J) which is currently being mapped under my user account.
When its trying to change the letter this is where i m getting an error.
I just want to see if someone can test the above script or see if there's a problem with the above script and advise.
Any direction is appreciated.
Thanks
Hoang.