# In was unexpected at this time - Batch file



## Anarkii (Mar 8, 2013)

Hi Forum 

I'm trying to create a batch file that users can run to display basic information on a pop-up window (must be batch file due to script restrictions), which they can read from when speaking to IT.

I've put some commands together and it works perfectly when pasted into a command prompt, but if I save the file as a .bat and try double-clicking, it doesn't work and I get "in was unexpected at this time" when I try running the file through cmd. I know that certain variables need two % when put into a batch file, but that's not the issue unfortunately.

The info we want to display is: Logged-on username, computer hostname, IP address, logged-on domain, logged-on domain controller, currently used proxy server and proxy exceptions.

As I say, all of this information displays (although I could only get exceptions to work in a separate window to proxy server) as it should do when pasted into cmd, just not when within a batch file (bad times!).

Any ideas? 

Here's my code so far:

```
set hostname=Hostname: %computername%
set user=User name: %username%
set dc=Domain Controller: %logonserver:\\=%
for /f "tokens=1-2 delims=:" %a in ('ipconfig^|find "IPv4"') do set ip=%b
for /f "tokens=1-2 delims=:" %c in ('ipconfig/all^|find "Primary Dns Suffix"') do set domain=%d
set domain=Domain: %domain:~1%
for /f "tokens=3 delims= " %1 in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"^| find /i "proxyserver"') do set proxy=%1
set proxy=Proxy Server: %proxy%
for /f "tokens=3,* delims= " %* in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"^| find /i "proxyoverride"') do msg %username% "=Computer Information="^
^
%user%^
^
%hostname%^
^
%ip%^
^
%domain%^
^
%dc%^
^
%proxy%^
^
=Press OK or close window to view Proxy Exceptions=
for /f "tokens=3,* delims= " %* in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"^| find /i "proxyoverride"') do msg %username% Proxy Exceptions: %*
```


----------



## foxidrive (Oct 20, 2012)

This works. It's a start for you to tweak.


```
@echo off
set hostname=Hostname: %computername%
set user=User name: %username%
set dc=Domain Controller: %logonserver:\\=%
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do set ip=%%b
for /f "tokens=1-2 delims=:" %%c in ('ipconfig/all^|find "Primary Dns Suffix"') do set domain=%%d
set domain=Domain: %domain:~1%
for /f "tokens=3 delims= " %%a in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"^| find /i "proxyserver"') do set proxy=%%a
set proxy=Proxy Server: %proxy%
for /f "tokens=3,* delims= " %%a in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"^| find /i "proxyoverride"') do msg %username% "=Computer Information=" %user% %hostname% %ip% %domain% %dc% %proxy% =Press OK or close window to view Proxy Exceptions=
for /f "tokens=3,* delims= " %%a in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings"^| find /i "proxyoverride"') do msg %username% Proxy Exceptions: %%a

pause
```


----------



## Squashman (Apr 4, 2003)

If the double % is not the issue then why doesn't your current code have them?

If they need to relay this information to IT helpdesk you should take a look at installing BGINFO on their computers.


----------



## Anarkii (Mar 8, 2013)

Thanks foxidrive  That worked a treat.

I was wondering if anyone was able to help further...

I've not been able to work out how to display all the info I need in a single window yet, and I'm sure it's possible, but clearly my knowledge of this isn't substantial enough.

What I'd like to display - in a single window - is the following:


Username
Hostname
IP address
Domain
Domain Controller
Current Proxy server
Proxy exceptions
All DNS servers
Is anyone able to assist?

Thanks in advance!


----------



## foxidrive (Oct 20, 2012)

Type this in a cmd prompt: WMIC 

Then type /? and press enter. See if the categories there have the information you need.
You can automate Wmic in a batch file too.


----------

