AutoHotkey Community

It is currently May 27th, 2012, 6:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: March 4th, 2011, 6:25 pm 
Offline

Joined: November 12th, 2010, 3:35 am
Posts: 63
Hi all. Here's my code.

Code:
#Singleinstance force
#NoTrayIcon

Gui, Add, Text,, Enter the PC name or IP.
Gui, Add, Edit, w200 vpcid
Gui, Add, Button,, Who?
Gui, Show,, Who's logged on?
return



ButtonWho?:
Gui, Submit, NoHide
Runwait, %comspec% /c "wmic /node:"%pcid%" computersystem get username >> c:\tools\usertoip\%pcid%.txt"
FileAppend, %pcid%, c:\tools\usertoip\%pcid%.txt
MsgBox,, %pcid% Logged On, Copied!
return

GuiClose:
exitapp


When I open the "appended file this is what I get.

UserName
DOMAIN\username
㤱⸲㘱⸸⸰㠱

Those what looks like chinese characters are supposed to be the PC name or IP I entered in the edit box... I'm sure I'm not seeing something here.

Thanks in advance.
Cheers!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2011, 6:51 pm 
Offline

Joined: March 8th, 2008, 11:36 am
Posts: 64
Location: Santa Barbara
My guess is the file you are appending to is a Unicode (UTF16) file but doesn't contain the Byte Order Mark (FF FE) at the very beginning to identify it as a Unicode (UTF16) file.

So AutoHotkey thinks it's a regular ANSI text file and is appending ANSI text to the Unicode file.

If you have a way to view the file's actual binary contents you may see zeros after every character until you come to the last line where you won't see the zeros after every character.

e.g. a Unicode UTF16(Little Endian) file containing "Hello" would be:
FF EE 48 00 65 00 6C 00 6C 00 6C 00 6F 00

The FF FE is the BOM that identifies this as a Unicode UTF16LE file,
48 00 = H
65 00 = E
6C 00 = L
6C 00 = L
6F 00 = O

Then appending ANSI text "HELLO" to that gives
FF EE 48 00 65 00 6C 00 6C 00 6C 00 6F 00 48 65 6C 6C 6F,
48 00 = H
65 00 = E
6C 00 = L
6C 00 = L
6F 00 = O
48 65 = some Chinese character
6C 6C = some Chinese character
6F ?? = ??

If the file already exists you could edit it in Notepad, do FILE -> SAVE AS, select Encoding as Unicode, and that should add the missing FF FE at the beginning of the file. Then future appends by AutoHotkey should work correctly; AutoHotkey will see it's a Unicode file and append Unicode text.

(Technically the BOM is not required for a Unicode file. Without it one is left to guess if it's a Unicode file or not. Sometimes Windows guesses wrong. See http://blogs.msdn.com/b/michkap/archive ... 62342.aspx)

_________________
http://www.autohotkey.net/~deleyd/xprxm ... amples.htm


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2011, 8:18 pm 
Offline

Joined: November 12th, 2010, 3:35 am
Posts: 63
Problem is I want this all done via command line in one swoop. I tried using:

Type file.txt > file.txt but that overwrites and deletes the info...

Anyway to have fileappend write as unicode? Prob not... I read wmic will only write as unicode too... Hmmm.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 5th, 2011, 6:07 pm 
Offline

Joined: March 8th, 2008, 11:36 am
Posts: 64
Location: Santa Barbara
The Unicode version of AutoHotkey will append Unicode text to a Unicode file. (That's the version I have installed and tested on.) Perhaps you could have AutoHotkey create the file first, then let wmic append to that file, then have AutoHotkey append the rest.

OK I tinkered a bit and came up with something that worked although it's not kosher, there may be a better way to achieve this. Here's what I did:

1. Write the AutoHotkey script and save it as a Unicode file (in Notepad, save as Encoding: Unicode).

2. In the AutoHotkey script, have it create the file with FileAppend, and all it writes is the BOF (hex FF FE, which displays as these two funny characters, a funny y with two dots and a funny b.)
Code:
FileAppend, ÿþ, test.txt


3. Then have wmic append to that file, and AutoHotkey append to that file, and hopefully wmic appends Unicode text (UTF16LE), and AutoHotkey will append to it as Unicode text, and you'll end up with a Unicode text file.

_________________
http://www.autohotkey.net/~deleyd/xprxm ... amples.htm


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hd0202 and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group