Figuring out which computer is being used at two different locations

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Yanta
Posts: 48
Joined: 01 Sep 2019 07:08

Figuring out which computer is being used at two different locations

#1 Post by Yanta » 07 Jul 2020 06:35

My son has a computer here and one at his other parents place.
The username is Corey on both computers, which he wants to keep.

I have a script which does a thousand different tweaks, installs and so on... It works by username.

His PC name is derived from %USERNAME%-PC. This is the standard that is used for the 10 PCs I have here.

I'm trying to modify the script so it knows which PC it's running on. At the point the script is run....

There are no network connections so a ping is out.
The PC name is the default DESKTOP-XXXXXXX random Windows one, so %USERDOMAIN% is out
whoami returns the same results on both PCs
Both are on the same windows version so winver is out.
Both have the same number of drives and drive letters are the same, none of which are labelled until halfway through the script
Other than motherboard drivers, no software, updates or anything else is installed.
I could use something like the system model from systeminfo, but every time a motherboard is changed the script has to be changed.

So far the only thing I've come up with is to set an environment variable at HKEY_CURRENT_USER\Environment, say called myLocation, but that has to be done manually and I'm trying to automate the whole process.

Any ideas?

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Figuring out which computer is being used at two different locations

#2 Post by penpen » 07 Jul 2020 07:28

Yanta wrote:
07 Jul 2020 06:35
The PC name is the default DESKTOP-XXXXXXX random Windows one, so %USERDOMAIN% is out
Unless you change that value every time you reboot your pcs, then i don't see, why it should be "out".
In case you change that value every time you reboot your pcs, then just don't change that value on reboot.


penpen

T3RRY
Posts: 243
Joined: 06 May 2020 10:14

Re: Figuring out which computer is being used at two different locations

#3 Post by T3RRY » 07 Jul 2020 09:28

Presuming the PC models are known and differ, you could use the PC model for comparison

(For /F "Delims=" %%G in ('wmic computersystem get Model /Format:Value') Do Set "%%G")>Nul

Yanta
Posts: 48
Joined: 01 Sep 2019 07:08

Re: Figuring out which computer is being used at two different locations

#4 Post by Yanta » 07 Jul 2020 19:29

penpen wrote:
07 Jul 2020 07:28
Yanta wrote:
07 Jul 2020 06:35
The PC name is the default DESKTOP-XXXXXXX random Windows one, so %USERDOMAIN% is out
Unless you change that value every time you reboot your pcs, then i don't see, why it should be "out".
In case you change that value every time you reboot your pcs, then just don't change that value on reboot.


penpen
I think you might not be understanding what this script is for. Twice yearly all 11 PCs are refreshed. 10 here, 1 where my son live part time. He has two computers. Windows is installed and then a setupcomplete.cmd type of script is run which tweaks settings, installs user applications, updates tasks and so on. At that point the PC only has the default windows name. It's random. You can't program around a random name. Sure, it's easy enough to retrieve the name but the code needs to know what name to look for.

This script is run once per install (assuming no crashes). Then not run again on that PC for 6 months, unless there are significant hardware changes.

So can't use %USERDOMAIN%.

Yanta
Posts: 48
Joined: 01 Sep 2019 07:08

Re: Figuring out which computer is being used at two different locations

#5 Post by Yanta » 07 Jul 2020 19:34

T3RRY wrote:
07 Jul 2020 09:28
Presuming the PC models are known and differ, you could use the PC model for comparison

(For /F "Delims=" %%G in ('wmic computersystem get Model /Format:Value') Do Set "%%G")>Nul
I thought of that. There are two problems (1). Motherboards are upgraded every 2 years so they never out of warranty and have resale value. Given the insane costs of technology in Australia I can only afford to do 3-4 PCs per year (2). Multiple of the same model are purchased. For example, there are multiple X299 XPower Gaming AC motherboards. The model numbers are the same.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Figuring out which computer is being used at two different locations

#6 Post by penpen » 08 Jul 2020 03:53

Yanta wrote:
07 Jul 2020 19:29
I think you might not be understanding what this script is for.
But maybe i did understand what the script is for;
contrary i think it's hard to imagine another usefull usage for such a script.

It seems you obviously never thought of pushing the setup while the old system is running, so you didn't get my hint:
Change the boot order to "[1] your usb, [2] hdd with system partition", then boot with the setup usb stick beeing plugged out. Insert your setup usb stick, call a "resetup.bat", which retrieves and stores some needed information onto your stick (for example <usb drive>:\ResetupInfo.txt) from the running system and then reboots that system, triggering the setup via boot order automatically executing your "setupcomplete.cmd", which deletes that information file, so if "setupcomplete.cmd" is executed from a new system it may behave differently (for example offfering a list of options in case you can't push from the old system while running - for example if you suspect it to be infected).


penpen

Yanta
Posts: 48
Joined: 01 Sep 2019 07:08

Re: Figuring out which computer is being used at two different locations

#7 Post by Yanta » 08 Jul 2020 05:28

@penpen I have a very primitive implementation of what you describe. Some time ago I believe you assisted me with a backup script which does capture and store information as well as backup the registry, application data and so on. The postinstall script then does the reverse and applies all those backups back to the pristine new system. But this doesn't solve me problem. This backup script captures the following information;

net start >"%RootDrv%\Logs\%USERDOMAIN%_ActiveServices.log"
wmic service list brief >"%RootDrv%\Logs\%USERDOMAIN%_Services.log"
driverquery /v >"%RootDrv%\Logs\%USERDOMAIN%_Drivers.log"
wmic product get name,version,description >"%RootDrv%\Logs\%USERDOMAIN%_InstalledPrograms.log"
schtasks /query /fo table /nh >"%RootDrv%\Logs\%USERDOMAIN%_ScheduledTasks.log"
systeminfo /FO "LIST" >"%RootDrv%\Logs\%USERDOMAIN%_PreInstall_SysInfo.log"
gpresult /f /scope "COMPUTER" /H "%RootDrv%\Logs\%USERDOMAIN%_Computer.html"
gpresult /f /scope "USER" /H "%RootDrv%\Logs\%USERDOMAIN%_User.html"
wmic qfe >"%RootDrv%\Logs\%USERDOMAIN%_Updates.Log"
wmic diskdrive list brief >"%RootDrv%\Logs\%USERDOMAIN%_Drives.Log"

The postinstall script is never initiated automatically because there are some things that need to be changed first.

When Windows is Installed ALL HDD and SSD must be disconnected from the system. Windows installation fails otherwise. There is more than one reason to disconnect the drives. I thought this was well known.

So, Disconnect all drives, install Windows, reconnect all drives, change drive letters, some other things, run script, connect network, run some more stuff.

But, let's do it your way. What information am I going to retrieve and store? Since the two PCs are identical how do I know which is which?

I do have an issue trying to figure out what drive some piece of software is installed on because there are two drives for games; One SSD and one HDD, but that's beside the point. The software is the same on both PCs.This is a script for configuring 11 PCs. Let's take an example, Runescape is on 6 of these PCs. On 3 it is on D: on 2 it is on E: and on the other it is on F:. The two PCs in question here it is on E:\. I'm trying not to be lazy and simply write a section of code for every user.

penpen
Expert
Posts: 1991
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Figuring out which computer is being used at two different locations

#8 Post by penpen » 08 Jul 2020 17:04

Yanta wrote:
08 Jul 2020 05:28
What information am I going to retrieve and store? Since the two PCs are identical how do I know which is which?
(First don't throw away your old resetup scripts.)

Just boot the pc you want to resetup next.
Then execute the "resetup.bat" (by doubleclicking that file on your USB drive) which somehow stores which PC to resetup next and then restart the system.

For example if you have pre existing setup scripts of the format "setup_%USERDOMAIN%.bat" for each pc (so if you have a pc with "%USERDOMAIN%" == "Destiny", you have a "setup_Destiny.bat") and a "setup_default.bat" for new pc's, then your "resetup.bat" might look like that:

Code: Select all

copy "setup_%USERDOMAIN%.bat" "setupcomplete.cmd" /Y
shutdown /r
Notes:
Backup your old "setupcomplete.cmd" first (although that might simply end up in the format "setup_%USERDOMAIN%.bat") , so you don't lose it!
Also the last command of each of those setup scripts should copy the "setup_default.bat" to "setupcomplete.cmd"; so you can install an unknown pc after that next if you wish.
If you need to disconnect anything you might use "shutdown /s" instead.
(You might also use a similar "resetup_default.bat".)
(if you don't like the shutdown command, then don't use that.)
(...)

So after you did that your USB-Stick "knows" which script to execute on next setup.



penpen

Yanta
Posts: 48
Joined: 01 Sep 2019 07:08

Re: Figuring out which computer is being used at two different locations

#9 Post by Yanta » 12 Jul 2020 01:30

I've read that a few times, but I'm not following it. Perhaps I'm just tired. I've been working with this script for days now.
I'll have to read it a few more times and get back to you.
At present I've just set an environment variable on each PC Called SYSTEMLOCATION. It's working perfectly, but as I said, it's a manual intervention.

siberia-man
Posts: 208
Joined: 26 Dec 2013 09:28
Contact:

Re: Figuring out which computer is being used at two different locations

#10 Post by siberia-man » 13 Jul 2020 00:43

As far as I understand your concern -- you need to distinguish two PCs that are set up identically. If everything (or more precisely -- almost everything) is similar each other, you need a way to find out their uniqueness or make them unique. I think you have already done it:
Yanta wrote:So far the only thing I've come up with is to set an environment variable at HKEY_CURRENT_USER\Environment, say called myLocation, but that has to be done manually and I'm trying to automate the whole process.
Yanta wrote:At present I've just set an environment variable on each PC Called SYSTEMLOCATION. It's working perfectly, but as I said, it's a manual intervention.
In addition...
Yanta wrote:The PC name is the default DESKTOP-XXXXXXX random Windows one (highlighted by me), so %USERDOMAIN% is out
... I'd like to say that PC name is something recognized via the %HOSTNAME% environment variable. You can rely on it, but it is changeable and is not 100% reliable. However it's the way.

Eureka!
Posts: 136
Joined: 25 Jul 2019 18:25

Re: Figuring out which computer is being used at two different locations

#11 Post by Eureka! » 13 Jul 2020 03:35

You can also define an asset tag in the BIOS - for example "Remote" - and check for the existence of that asset tag using a WMI query.

Or: right before starting your script, connect some random USB stick to this machine that has volume label "Remote" and check for the existence of that (wmic volume where Label="Remote" ). Remove the USB-stick afterwards.

Or: check for location specific peripherals, like a printer

kwsiebert
Posts: 42
Joined: 20 Jan 2016 15:46

Re: Figuring out which computer is being used at two different locations

#12 Post by kwsiebert » 13 Jul 2020 09:15

You said there's no network connection, but there's still almost assuredly a network adapter present, right? In that case, you should be able to get the MAC address, which will still be unique.

Yanta
Posts: 48
Joined: 01 Sep 2019 07:08

Re: Figuring out which computer is being used at two different locations

#13 Post by Yanta » 28 Jul 2020 21:34

Thanks everyone. Lots of great ideas!

@siberia-man: Yes, this manual process works. I was trying to automate the process, but have not yet found a way. The PC Name when Windows is installed is random. The script I'm writing actually changes the name into something more meaningful, but it can't be used to determine the location of the PC.

@Eureka!: There are no printer drivers installed. The only printer here is a LAN attached Canon MX870. As there is no LAN connection the device couldn't be detected any way. The LAN has to be operational for the printer driver installer to detect and configure it. I'll have a look at the asset tag in the bios. I've never heard of it, but it's worth looking into. Note though, that this is still a manual process.

@kwsiebert: Yes, Network adapters are present on the motherboard, or in the case of several machines, installed 10G adapters in PCIe slots. However, there are no drivers installed and Windows does not "see" the NICs because they are disabled in the BIOS* Several of the PCs have 3 NICs, Most have WiFi and a couple have two NICs. The only issue I have with NICs is every time I Upgrade a motherboard, or change an adapter I have to change the script. The goal was to automate the process. Setting an environment variable on the PC is better only because every time the script is changed I have to send copies out to multiple non-technical people.

* NICs are disabled in the BIOS as well as being unplugged to (a). Force Windows to allow me to create a local account not a Microsoft Account (2). Prevent Windows installing drivers for them. I prefer vendor specific drivers rather than generic Microsoft drivers. Even though Windows can't connect to Windows update to do its initial telemetry dump and driver download, Windows still has drivers available to it to install during the installation.

NICs are not enabled until the very end of the script when WSUS policies have been configured to prevent Windows from downloading drivers (or anything for that matter), from anywhere but my WSUS server. In this way I can manage when patches are applied, and make sure Microsoft's aggressive pushes on to new versions of the OS are blocked. The last thing I need is 10 PCs crashing every other day with a new version of Windows that I haven't had time to test against all applications we run here.

I think we've about exhausted all the possibilities. If I ever find a way to accomplish an automated way to detect where a PC is connected, I'll try to remember to come back here and update this thread.

Post Reply