Welcome to OCS Inventory NG community support, where you can ask questions and receive answers from other members of the community.

Please ask questions only in English or French.

Release 2.12.3 available

The official documentation can be found on https://wiki.ocsinventory-ng.org. Read it before asking your question.

Not a solution your answer

Uninstaller has been run with admin privileges... and OCSService.exe are still there (locked).

Service was properly stopped, uninstalled, but file seems to be already in use.

Using "Unlocker" application or "Process Explorer" there is no way to find an handle to a process that keep file in use?!?!

Also killing Explorer.exe...

Please find a solution to this (may be when stopping OCSService on your code close all open "task" before)
related to an answer for: Upgrading OCS Inventory Agent
in OCS Inventory NG agent for Windows by (140 points)

1 Answer

0 votes
Hello,

Personnally I use this script :

If WScript.Arguments.Named.Exists("elevated") = False Then
  CreateObject("Shell.Application").ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """ /elevated", "", "runas", 1
  WScript.Quit
End If
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")

    Dim OCS
    ' Uninstall agent ocs if is installed
    ' Verification on OS 32 Bits
    On error resume next
    OCS = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory Agent\UninstallString")
    If err.number = 0 then
        WshShell.Run "CMD.EXE /C net stop ""OCS INVENTORY SERVICE""",0,True
        WshShell.Run "CMD.EXE /C """ & OCS & """ /S /NOSPLASH",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles%\OCS Inventory Agent"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%SystemDrive%\ocs-ng"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramData%\OCS Inventory NG"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C sc delete ""OCS INVENTORY""",0,True
    End If

    ' Verification on OS 64 Bits
    On error resume next
    OCS = WshShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory Agent\UninstallString")
    If err.number = 0 then
        WshShell.Run "CMD.EXE /C net stop ""OCS INVENTORY SERVICE""",0,True
        WshShell.Run "CMD.EXE /C """ & OCS & """ /S /NOSPLASH",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles(x86)%\OCS Inventory Agent"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%SystemDrive%\ocs-ng"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramData%\OCS Inventory NG"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C sc delete ""OCS INVENTORY""",0,True
    End If

    ' Verification Agent V2 on 32Bit
    On error resume next
    OCS = WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory NG Agent\UninstallString")
    If err.number = 0 then
        WshShell.Run "CMD.EXE /C net stop ""OCS INVENTORY SERVICE""",0,True
        WshShell.Run "CMD.EXE /C taskkill /F /IM ocssystray.exe",0,True
        WshShell.Run "CMD.EXE /C """ & OCS & """ /S /NOSPLASH",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles%\OCS Inventory Agent"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%SystemDrive%\ocs-ng"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramData%\OCS Inventory NG"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C sc delete ""OCS INVENTORY""",0,True
    End If

    ' Verification Agent V2 on 64Bit
    On error resume next
    OCS = WshShell.RegRead("HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\OCS Inventory NG Agent\UninstallString")
    If err.number = 0 then
        WshShell.Run "CMD.EXE /C net stop ""OCS INVENTORY SERVICE""",0,True
        WshShell.Run "CMD.EXE /C taskkill /F /IM ocssystray.exe",0,True
        WshShell.Run "CMD.EXE /C """ & OCS & """ /S /NOSPLASH",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramFiles%\OCS Inventory Agent"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%SystemDrive%\ocs-ng"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C rmdir ""%ProgramData%\OCS Inventory NG"" /S /Q",0,True
        WshShell.Run "CMD.EXE /C sc delete ""OCS INVENTORY""",0,True
    End If

Err.Clear
On Error Goto 0
by (4.9k points)
 
Powered by Question2Answer
...