Page 1 of 1

WMIC Remote uninstall [SOLVED]

Posted: 28 May 2012 03:36
by SMAndy
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

Re: WMIC Remote uninstall

Posted: 28 May 2012 03:49
by foxidrive
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.

Re: WMIC Remote uninstall

Posted: 28 May 2012 03:54
by SMAndy
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!

Re: WMIC Remote uninstall

Posted: 28 May 2012 04:05
by foxidrive
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"

Re: WMIC Remote uninstall

Posted: 28 May 2012 05:05
by SMAndy
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?

Re: WMIC Remote uninstall

Posted: 28 May 2012 18:10
by Ed Dyreen
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.

Re: WMIC Remote uninstall

Posted: 27 Jul 2012 03:17
by SMAndy
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...

Re: WMIC Remote uninstall [SOLVED]

Posted: 27 Jul 2012 07:20
by Squashman
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.