Is there a command for use in a batch file that will let you run something only if it is a certain computer name, logon name, etc?
New: Run-Command (Dec 2, 2024), Platform 29.5.3 (Jun 27, 2024)
1,100+ portable packages, 1.1 billion downloads
No Ads Nov/Dec!, Please donate today
for it but I think the script will run only if it's an admin account.
OliverK> you don't live on a cow
IRC: It brings out the best in all of us...Especially when tired.
This is modified from a script I use, but it's not the most efficient way to use the IF-ELSE command. Use Google or "if /?" on the command line for info on how to modify it.
The key is to evaluate the machine name then do an action if it's true and nothing if it's false.
Swap in %USERNAME% for...drumroll....the username.
Type "set" in a command prompt to see a whole bunch of environment variables you can use.
Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!
Side question:
How do you get the current computer name automatically?
~Lurk~
Just like the post above. It's an environment variable. At a cmd prompt type
echo %computername%
I mean to use at another spot in the batch, without typing it in. Maybe IP would be better instead. Some thing like:
I wish I could find where I was reading about this again...
~Lurk~
I'm not sure I know what you mean by using it without typing it in. And are you looking for the computer name or the IP address now? You can use %computername% anywhere in your batch script to insert the computer's name.
I can already get the IP range for the current network. Now I would like to exclude the host machine by name or IP, whichever is easier. I was just thinking that since I would already be pinging each IP address in the given range, it might be easier to exclude by IP rather than name. Sorry for the confusion, I hope this is clearer.
~Lurk~
That would be done a LOT easier with a VBScript rather than a batch file.
Is this a login script? Where are you using this and what's the overall idea? That info may help us, help you better.
Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!
It is possible to shutdown (at least a XP) PC over a network. My idea was to automate the process to handle multiple PCs. I know there are limitations, like having to have same UN & PW.
I have succeeded, to a point. I can get the IP range, ping each IP, & send shutdown signal upon positive response. I just need to get the local IP and exclude it from shutdown.
~Lurk~
I see your point.
This still sounds like a PITA without the use of an array or "real" looping like you would have in a scripting language (any of them). The only way I can think of doing it in a batch file would to be to split the range into two halves with localhost IP being the dividing line.
(Example assumes a subnet mask of 255.255.255.0 or /24 in CIDR so only the fourth octet "matters")
network = 192.168.1.x
localmachine = 192.168.1.78
Spliting on the local machine would give you two ranges or groups of IPs to ping.
.1 thru .77 and .79 thru .255
Cancer Survivors -- Remember the fight, celebrate the victory!
Help control the rugrat population -- have yourself spayed or neutered!
Here is a test batch I was working on many moons ago. (REMs removed) Maybe you or someone else can help me straighten this out...
~Lurk~
Well typing 'set' at a command prompt will give you all sorts of useful environment variables.
%computername%
or
%logonserver%
should get you what you need. They will expand and work inside your BAT script.