Help modifying this .vbs

Discussion in 'Windows 10' started by IAmTheDude, Aug 12, 2015.

  1. IAmTheDude

    IAmTheDude MDL Member

    Oct 12, 2011
    112
    19
    10
    #1 IAmTheDude, Aug 12, 2015
    Last edited by a moderator: Apr 20, 2017
    Hey all :)

    Stumbled upon this little vbs that turns OneDrive on and off. Works great in 7 & 10.

    I wanted to modify it for other cloud apps like Dropbox and GDrive but, well, I suck at coding.

    Ive tried the obvious, changing the name and paths but Im just getting an error.

    Original OneDrive Toggle:

    Code:
    set objWMIService = GetObject ("winmgmts:") foundProc = False
     procName = "OneDrive.exe"
    
    
     for each Process in objWMIService.InstancesOf ("Win32_Process")
         If StrComp(Process.Name,procName,vbTextCompare) = 0 then
             foundProc = True
             procID = Process.ProcessId
         End If
     Next
     If foundProc = True Then
         Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" &  procID)
         For Each objProcess in colProcessList    
             objProcess.Terminate()
         Next
         WScript.Sleep(1000) 'wait for a second
         Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" &  procID)
         If colProcessList.count = 0 Then
             msgbox "OneDrive is now closed.", 0 & 64,"OneDrive"
         End If
    else
    WScript.CreateObject("WScript.Shell").Run("%LocalAppData%\Microsoft\OneDrive\OneDrive.exe")
    End If


    Attempt at Dropbox: (ninite installer paths, think normal installs elsewhere)

    Code:
    set objWMIService = GetObject ("winmgmts:")
     foundProc = False
     procName = "Dropbox.exe"
    
    
     for each Process in objWMIService.InstancesOf ("Win32_Process")
         If StrComp(Process.Name,procName,vbTextCompare) = 0 then
             foundProc = True
             procID = Process.ProcessId
         End If
     Next
     If foundProc = True Then
         Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" &  procID)
         For Each objProcess in colProcessList    
             objProcess.Terminate()
         Next
         WScript.Sleep(1000) 'wait for a second
         Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" &  procID)
         If colProcessList.count = 0 Then
             msgbox "Dropbox is now closed.", 0 & 64,"Dropbox"
         End If
    else
    WScript.CreateObject("WScript.Shell").Run("C:\Program Files (x86)\Dropbox\Client\Dropbox.exe")
    End If

    Attempt at GDrive:

    Code:
    set objWMIService = GetObject ("winmgmts:")
     foundProc = False
     procName = "googledrivesync.exe"
    
    
     for each Process in objWMIService.InstancesOf ("Win32_Process")
         If StrComp(Process.Name,procName,vbTextCompare) = 0 then
             foundProc = True
             procID = Process.ProcessId
         End If
     Next
     If foundProc = True Then
         Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" &  procID)
         For Each objProcess in colProcessList    
             objProcess.Terminate()
         Next
         WScript.Sleep(1000) 'wait for a second
         Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" &  procID)
         If colProcessList.count = 0 Then
             msgbox "Googel Drive is now closed.", 0 & 64,"OneDrive"
         End If
    else
    WScript.CreateObject("WScript.Shell").Run("C:\Program Files\Google\Drive\googledrivesync.exe")
    End If

    Attempt at Skype:

    Code:
    set objWMIService = GetObject ("winmgmts:")
     foundProc = False
     procName = "Skype.exe"
    
    
     for each Process in objWMIService.InstancesOf ("Win32_Process")
         If StrComp(Process.Name,procName,vbTextCompare) = 0 then
             foundProc = True
             procID = Process.ProcessId
         End If
     Next
     If foundProc = True Then
         Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" &  procID)
         For Each objProcess in colProcessList    
             objProcess.Terminate()
         Next
         WScript.Sleep(1000) 'wait for a second
         Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" &  procID)
         If colProcessList.count = 0 Then
             msgbox "Skype is now closed.", 0 & 64,"Skype"
         End If
    else
    WScript.CreateObject("WScript.Shell").Run("C:\Program Files (x86)\Skype\Phone\Skype.exe")
    End If





    Basically, if the app is running it closes it and if it isnt it starts it up.

    At a loss really, its all a foreign language to me :(

    If any one could point out whats wrong it would be much appreciated!
     
  2. bleedlikeme

    bleedlikeme MDL Novice

    Jul 24, 2015
    18
    4
    0
    #2 bleedlikeme, Aug 13, 2015
    Last edited by a moderator: Apr 20, 2017
    Enclose the paths containing spaces with double quotes like this...


    Dropbox:

    Code:
    WScript.CreateObject("WScript.Shell").Run("""%ProgramFiles(x86)%\Dropbox\Client\Dropbox.exe""")
    
    OR
    Code:
    WScript.CreateObject("WScript.Shell").Run("""C:\Program Files (x86)\Dropbox\Client\Dropbox.exe""")
    


    GDrive:

    Code:
    WScript.CreateObject("WScript.Shell").Run("""%ProgramFiles%\Google\Drive\googledrivesync.exe""")
    
    OR
    Code:
    WScript.CreateObject("WScript.Shell").Run("""C:\Program Files\Google\Drive\googledrivesync.exe""")
    


    Skype:

    Code:
    WScript.CreateObject("WScript.Shell").Run("""%ProgramFiles(x86)%\Skype\Phone\Skype.exe""")
    
    OR
    Code:
    WScript.CreateObject("WScript.Shell").Run("""C:\Program Files (x86)\Skype\Phone\Skype.exe""")
    


    Hope this helps!
     
  3. IAmTheDude

    IAmTheDude MDL Member

    Oct 12, 2011
    112
    19
    10
    :worthy:

    Absolute legend!

    Many many thanks for that, much appreciated!!