WMIC Remote uninstall [SOLVED]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SMAndy
Posts: 8
Joined: 28 May 2012 03:23

WMIC Remote uninstall [SOLVED]

#1 Post by SMAndy » 28 May 2012 03:36

Hi All,

This is my first post, and I'm hoping i'll get a good impression by getting an answer to my first issue. Batch files are the only way of scripting that I know, and I like to think i'm getting pretty good at it.

I've written this file:

@echo off
::Ask for Target PC Name
SET target=
SET /P target=Type Target PC Name Here:

wmic /node:"%target%" product where vendor="Mindjet LLC" call uninstall

in order to remove installations of Mind Manager remotely. Now, the weird thing is that when no one is logged into the target PC, it works fine. ReturnValue is 0, and when i then log on, it's all done.

However, if someone is logged into the target PC, it fails with ReturnValue 1603. I know this can be to do with rights, but since i run my Win7 PC in test mode, with UAC turned off, everything comes up with admin rights anyway.

Any ideas? I've tried adding a /nointeractive switch as i've seen on some websites, and i've also tried adding a /interactive:off switch too, but none seem to make a difference. I've logged in on the target PC with both my login, and a random other login to check. I know my script is good because it works when no one is logged in. Would it work better if i used an @file for the node? If so, I have another command underneath this (PSEXEC to run an uninstall file that can't be removed using WMIC). How do i make a normal batch file command work on a text file?

Thanks.

Andy
Last edited by SMAndy on 27 Jul 2012 03:17, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: WMIC Remote uninstall

#2 Post by foxidrive » 28 May 2012 03:49

SMAndy wrote:How do i make a normal batch file command work on a text file?


What do you mean?

Regarding the logged in issue - when noone is logged in it would use the system account. If you schedule it to use the system account then maybe it will work when people are logged in.

Or... check the logs and see if the files aren't being removed because they are in use. Someone Logging in may cause the files to be loaded.

SMAndy
Posts: 8
Joined: 28 May 2012 03:23

Re: WMIC Remote uninstall

#3 Post by SMAndy » 28 May 2012 03:54

sorry, that was badly worded..

What i mean is something like...

for each item in (target file), run this command. so i can run a psexec on a number of PC's, listed in a text file that I can store somewhere on my pc.

Do you know how i force it to run with the system account? PSEXEC has a switch that's just something like -s to use the system account... I'll have a play with the /user: switch.

Thanks for replying!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: WMIC Remote uninstall

#4 Post by foxidrive » 28 May 2012 04:05

SMAndy wrote:for each item in (target file), run this command.



@echo off
for /f "delims=" %%a in (' type "abc.txt"') do echo psexec -blah "%%a"

SMAndy
Posts: 8
Joined: 28 May 2012 03:23

Re: WMIC Remote uninstall

#5 Post by SMAndy » 28 May 2012 05:05

It's not that the files are in use, so it can't remove them... If i run the command on a local PC (removing the /node part) the wmic uninstall works fine.

the problem is that if i open a command prompt, and type wmic first to get it into that mode, all commands work fine. I can remotely uninstall stuff, and there's no trouble there.

However, running the script comes back with what I can only see as "invalid query" (i tried running the command in powershell, because that's often more verbose)... but if i go into wmic mode first, it all works fine.

Issue there is if i put "wmic" as a line in my batch file, it just sits there and doesn't go onto the next line. My batch file window just sits on "wmic:root\cli>" and waits for input.

Any ideas?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: WMIC Remote uninstall

#6 Post by Ed Dyreen » 28 May 2012 18:10

SMAndy wrote:Issue there is if i put "wmic" as a line in my batch file, it just sits there and doesn't go onto the next line. My batch file window just sits on "wmic:root\cli>" and waits for input.
'
That's weird, it works perfectly over here.

Code: Select all

@echo off

WMIC.EXE path WIN32_USERACCOUNT get Name

exit /b %errorLevel%
You can use foxidrive's solution to catch the result in a variable.

SMAndy
Posts: 8
Joined: 28 May 2012 03:23

Re: WMIC Remote uninstall

#7 Post by SMAndy » 27 Jul 2012 03:17

I managed to fix this myself, using psexec.

psexec \\%target% -s -i -u %userdomain%\%username% cmd /c wmic product where vendor="Mindjet" call uninstall

This command works fine :) Brings a command prompt up on their screen, but it does the job! I've written a file that prompts them before it uninstalls so they know whats going on, and don't cancel it...

I think I'm getting quite good at psexec...

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: WMIC Remote uninstall [SOLVED]

#8 Post by Squashman » 27 Jul 2012 07:20

SMAndy wrote:Hi All,

This is my first post, and I'm hoping i'll get a good impression by getting an answer to my first issue. Batch files are the only way of scripting that I know

Vbscript is another good thing to learn and Powershell is the future according to MS.

Post Reply