开发者

Update VBScript to work with Windows 7

I am currently running windows XP Pro on my domain computers and in the process of migrating to Windows 7.

I have a schedule task that runs a VB script at login that assigns a partition to the current user.

Here is a breakdown of the setup,

   -80 GB hard drive
   -30 GB system partition
   -10 GB partition (DMW Drive)
   -10 GB partition (DTH Drive) 
   -10 GB partition (NMW Drive)
   -10 GB partition (NTH Drive)

The script assigns the correct drive according to the time of the login. We use this to have a storage place for users to have full access to save their data.

This runs perfectly on XP but does not run on Windows 7.

Here is the script.

set wshshell = wscript.CreateObject("Wscript.Shell")
    iReturn = WshShell.Run("Diskpart.exe /s removeall.txt", 1, True)
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime", , 48)
For Each objItem In colItems
    DayOfWeek = objItem.DayOfWeek
    HourOfDay = objItem.Hour
Next
    If DayOfWeek = 1 Or DayOfWeek = 3 Then
        If HourOfDay >= 6 And HourOfDay <= 13 Then
            iReturn = WshShell.Run("Diskpart.exe /s Aset.txt", 1, True)
        End If
        If HourOfDay >= 15 And HourOfDay <= 22 Then
            iReturn = WshShell.Run("Diskpart.exe /s Cset.txt", 1, True)
        End If
    End If
    If DayOfWeek = 2 Or DayOfWeek = 4 Then
        If HourOfDay >= 6 And HourOfDay <= 13 Then
            iReturn = WshShell.Run("Diskpart.exe /s Bset.txt", 1, True)
        End If
        If HourOfDay >= 15 And HourOfDay <= 22 Then
            iReturn = WshShell.Run("Diskpart.exe /s Dset.txt", 1, True)
        End If
    End If

Here are the text files that the script calls on.

ASet.txt = select volume 2
       assign
BSet.txt = select volume 3
       assign
CSet.txt = select volume 4
       assign
DSet.txt = select volume 5
       assign

Removeall.txt = 
              select volume 2
              re开发者_JAVA百科move noerr
              select volume 3
              remove noerr
              select volume 4
              remove noerr
              select volume 5
              remove noerr

Any input will be appreciated.

Thank you.


Since diskpart requires elevation, you need to configure the scheduled task to run elevated ("Run with highest privileges" on the General tab of task properties).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜