Start Defrag on a Target Machine (VBS)

Home Forums Scripting General Scripting Start Defrag on a Target Machine (VBS)

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    Lan
    Member
    #126442

    I have this little script to start off Defrag on a machine… it only works on the local machine, opens a window, runs the defrag and closes when its finished… works fine, but only if you are an administrator sadly…

    Set WshShell = WScript.CreateObject(“WScript.Shell”)

    Dim fso, d, dc
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set dc = fso.Drives
    For Each d in dc
    If d.DriveType = 2 Then
    Return = WshShell.Run(“defrag ” & d, 1, TRUE)
    End If
    Next

    Set WshShell = Nothing[/CODE]

    I do get a fair few people asking to start off defrag and then leave them to it – it’s a pain connecting to their machine, running defrag/the script as myself…

    I’d like to be able to just double click – type in the comp name and let it go away and start the defrag process – I assume since I’d run it from my machine it’d run as me – which is fine as I’d have admin rights on the machine so it’d prevent all those pesky user without permission problems.

    I know I could use things like the PStools:
    [CODE]PSEXEC -i -d -s \ c:windowssystem32defrag.exe c:[/CODE]
    but I want to be able to just enter the computer name rather than edit it into a batch file all the time…

    Any ideas?[CODE]Set WshShell = WScript.CreateObject(“WScript.Shell”)

    Dim fso, d, dc
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set dc = fso.Drives
    For Each d in dc
    If d.DriveType = 2 Then
    Return = WshShell.Run(“defrag ” & d, 1, TRUE)
    End If
    Next

    Set WshShell = Nothing[/CODE]

    I do get a fair few people asking to start off defrag and then leave them to it – it’s a pain connecting to their machine, running defrag/the script as myself…

    I’d like to be able to just double click – type in the comp name and let it go away and start the defrag process – I assume since I’d run it from my machine it’d run as me – which is fine as I’d have admin rights on the machine so it’d prevent all those pesky user without permission problems.

    I know I could use things like the PStools:
    PSEXEC -i -d -s \ c:windowssystem32defrag.exe c:[/CODE]
    but I want to be able to just enter the computer name rather than edit it into a batch file all the time…

    Any ideas?[CODE]PSEXEC -i -d -s \ c:windowssystem32defrag.exe c:[/CODE]
    but I want to be able to just enter the computer name rather than edit it into a batch file all the time…

    Any ideas?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.