getting remote drivernodes using "devcon drivernodes" - vbscript

I was trying to get the below information related to the drivers.
Name, INFFile, Vendor, Version, Description, and Date.
All the information i could find it using the below command.
"devcon drivernodes"
But this is only working in local machine. (Checked with MSDN and came to know that we cannot get the remote machine details with this command.
Do we have any other utility / way to get the mentioned details from a remote computer?
I am capturing all the details using VBScript (using .exec method and stdout.readline method)
Thanks in Advance

Does
wmic /node:computerlist.txt sysdriver get /format:list
Computerlist.txt is a list of IP addresses or computernames.
For local computer
wmic sysdriver get /format:list
See wmic /? (for a partial list of what's available), wmic sysdriver get /?, and wmic /format /?.
EDIT
To get file versions, if a file has one. Note backslashes have to be doubled.
Filever.bat filename
set filepath=%~f1
set file=%filepath:\=\\%
wmic datafile where name^="%file%" get version|findstr /i /v /c:"version"
To start a program (it will be invisible on remote computers)
wmic process call create c:\\windows\\notepad.exe

Related

How to only run WMIC if it has already been installed?

I am trying to run a batch file that includes some WMIC queries on multiple versions of Windows. Windows 2003 causes the script to hang. It is most likely due to the first time that wmic is being run. The computer will normally output "Please wait while WMIC is being installed.."
Is there anyway to check if wmic is installed and if it is not, do not run it? I do not want to install WMIC on the computers I am running this on if it is not already installed. Should I just skip this query on all Windows 2003?
May be I'm wrong, but I think wmic is present at least from XP
This may help
#echo off
where /R c:\windows\ wmic.exe >nul 2>nul || (echo/ wmic.exe not found & exit/B)
rem wmic queries here
exit/B

Batch File execution on remote windows server via batch file on another windows server

I am trying to call a batch file placed on a remote windows server from my windows server. I have freeSSHd installed on the remote server. I tried using putty/plink but of no result.
Syntax of command I am using is:
Putty: start E:\putty.exe -ssh user12#serverIP -pw "abcd12" call sample.bat
Plink: start E:\plink.exe -ssh user12#serverIP -pw "abcd12" cmd.exe -m E://sample.txt
I even tried all variants of above two commands like "-m file.txt" etc. Also I am able to execute batch file via login into putty console but not via calling batch file placed on my windows server.
This is how to start remote programs in Windows.
wmic /node:servername process call create "cmd.exe c:\\somefolder\\batch.bat"
Files executed this way are invisible on the remote computer.
For Help
wmic /?
wmic process /?
wmic process get /?
wmic process set /?
wmic process call /?
wmic process call create /?
wmic process /node /?
wmic process /user /?
wmic process /password /?

How to stop a service in cmd only knowing the name of the .exe file?

I need to stop a windows service in a batch file without knowing the name of the service. The only thing I know is that the file running is called SomeServer.exe but the SC command requires the actual name of the service.
Currently I have to scan a config file and perform ugly string operations but I hope there is a smarter way.
Any suggestions?
for /f "tokens=2 delims=," %%a in (
'wmic service get name^,pathname^,state /format:csv ^| findstr /i /r /c:"SomeServer\.exe.*Running$"'
) do sc stop "%%a"
It retrieves the system name, service name, path name and state of the services in csv format. The list is filtered for the required executable name in Running state, splitted using the comma as separator, and the second field (the service name) is used to stop the service
this may be helpfull
http://richarddingwall.name/2009/06/18/windows-equivalents-of-ps-and-kill-commands/
If you’ve ever used Unix, you’ll no doubt be well-aquainted with the
commands ps and kill. On Windows, the graphical Task Manager performs
these roles pretty well, but if you ever find yourself needing to
resort to the command line to kill a process (e.g. for some reason on
the Vista machine I am writing this on Task Manager just sits in the
system tray flashing instead of opening), the Windows equivalents of
ps and kill are tasklist and taskkill:
tasklist /v - equivalent to ps aux
taskkill /f /im ncover* - equivalent to kill -9 ncover*
and there is also pslist http://technet.microsoft.com/en-us/sysinternals/bb896682.aspx
edit:
for services use psservice http://technet.microsoft.com/en-us/sysinternals/bb897542.aspx
or use the method described here (using the registry) https://stackoverflow.com/a/298823/1342402

How to display my PC's IP Address on Windows (7) Startup?

I am on a work computer with dynamic IP address (Ipv4), which usually changes when I restart it. Since I sometimes need to use this PC through remote desktop connection at home I like to keep its IP address handy. But I sometimes forget to check the IP at restart, so is there a batch file or some code which can start up the cmd and display the IPv4 address everytime the computer restarts ?
thanks.
Simple, just create a batch file that runs ipconfig and displays the output:
start cmd /k ipconfig
exit
You'll see a console window appear on your screen each time you execute this batch file that contains the output of the ipconfig command. Among the information displayed will be the IP address for each of your computer's network adapters.
You can configure the command as appropriate, adding switches to ipconfig as desired. For example, adding the /all switch will cause additional information to be displayed.
If you wanted, you could parse the output of ipconfig, extract the IP address assigned to a particular network adapter, and display just that on the screen. That might reduce the cognitive overload. But any good Windows sysadmin can scan the output of ipconfig rather easily.
You can set a batch file to run upon startup.
The batch file should contain:
ipconfig
pause
I used this in a .bat file I created some days ago and it works fine:
#echo off
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do set ip=%%b
set ip=%ip:~1%
echo %ip%
This way the IP is defined as a variable named "ip", so you can use this to do other things with your current IP.
I hope it helped somehow.

Why does batch file FOR fail when iterating over command output?

I have a batch file that uses this idiom (many times) to read a registry value into an environment variable:
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName') DO SET MyVariable=%%B
(There's a tab character after delims=)
This works fine on thousands of customer's computers. But on one customer's computer (running Windows Server 2003, command extensions enabled),
it fails with 'REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName' is not recognized as an internal or external command, operable program or batch file.' Running the "reg query" command alone works fine. Reg.exe is present in C:\Windows\System32.
I was able to work around the problem by changing the code to
REG QUERY "HKLM\SOFTWARE\Path\To\Key" /v ValueName > temp.txt
FOR /F "tokens=2* delims= " %%A IN (temp.txt) DO SET MyVariable=%%B
This got the customer up and running, but I would like to understand why the problem occurred so I can avoid it in the future.
Slightly off the primary topic - a more direct way to get a registry value (string or DWORD) into an environment variable would also be useful.
I would check:
The customer's role on the machine - are they an admin?
Where is reg.exe on the box - is there more than one copy of copy of reg.exe in the path?
Is there any locale difference on the customer's machine from the machines where this normally works?
Basically, enumerate everything that differs between this machine and machines where it works as expected. Include service packs, domain membership, etc.
Wow, that is odd.
If the same commands work when split into two lines, then I'd guess it has something to do with the way the command gets run in a subshell in the FOR command.
If you were really dying to figure out why it's dying in this particular case, you could run commands like "SET > envvars.txt" as the FOR command and compare that with the top shell.
Or maybe start off simple and try running the REG command via CMD /C to see if that does anything?
One quick guess here, what's the values of COMSPEC and SHELL ?
I had a similar situation to this. In my case it was a bad value in COMSPEC. I fixed that and the script started working as expected.
The /F switch needs command extensions to be turned on. Usually they are turned on by default, but I'd check that. On XP systems you can turn them on doing something like
cmd /e:on
or checking the registry under
HKCU\Software\Microsoft\Command Processor\EnableExtensions
Dunno about Windows Server.
Doing help for and help cmd could provide some hints as well.

Resources