Jump to content

rename text file to computername


can7
 Share

Recommended Posts

Hi Everybody

I trying to write a script to get the PC info on my network and input in a text file.

I would like to name the text file with the computername.

How would I do this?

I have been searching this forum and came up with this script so far.

#include <file.au3>

$UserName = @UserName
$LogonDomain = @LogonDomain
$PCName = @ComputerName
$IPAdress = @IPAddress1
$WinVer = @OSVersion    
$ServicePack = @OSServicePack



Func _GetMACFromIP($sIP)
    Local $MAC, $MACSize
    Local $i, $s, $r, $iIP
    $MAC = DllStructCreate("byte[6]")
    $MACSize = DllStructCreate("int")
    DllStructSetData($MACSize, 1, 6)
    $r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
    $iIP = $r[0]
    $r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
    $s = ""
    For $i = 0 To 5
        If $i Then $s = $s & ":"
        $s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
    Next
    Return $s
EndFunc   ;==>_GetMACFromIP
$IP = $IPAdress
$MAC = _GetMACFromIP($IP)

FileWrite(@ScriptDir & "\Text.txt", $UserName & @CRLF)
FileWrite(@ScriptDir & "\Text.txt", $PCName & @CRLF)
FileWrite(@ScriptDir & "\Text.txt", $IPAdress & @CRLF)
FileWrite(@ScriptDir & "\Text.txt", $WinVer & @CRLF)
FileWrite(@ScriptDir & "\Text.txt", $MAC & @CRLF)

; FileWrite(@ScriptDir & "\Text.txt", $PCName & @CRLF)
; FileWrite(@ScriptDir & "\Text.txt", $IPAdress & @CRLF)


_FileWriteLog(@ScriptDir & "\Text.txt","date and time")

Can7

Link to comment
Share on other sites

#include <file.au3>

$UserName = @UserName
$LogonDomain = @LogonDomain
$PCName = @ComputerName
$IPAdress = @IPAddress1
$WinVer = @OSVersion    
$ServicePack = @OSServicePack



Func _GetMACFromIP($sIP)
    Local $MAC, $MACSize
    Local $i, $s, $r, $iIP
    $MAC = DllStructCreate("byte[6]")
    $MACSize = DllStructCreate("int")
    DllStructSetData($MACSize, 1, 6)
    $r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
    $iIP = $r[0]
    $r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
    $s = ""
    For $i = 0 To 5
        If $i Then $s = $s & ":"
        $s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
    Next
    Return $s
EndFunc   ;==>_GetMACFromIP
$IP = $IPAdress
$MAC = _GetMACFromIP($IP)
$sTxt = $UserName & @CRLF & $PCName & @CRLF & $IPAdress & @CRLF
$sTxt &= $WinVer & @CRLF & $MAC & @CRLF
$sText &= @Year & @Mon & @MDay & "  " & @Hour & ":" & @Min & ":" & @Sec
$hFile = FileOpen(@ScriptDir & "\" & $PCName & ".txt", 2)
FileWrite($hFile, $sTxt)
FileClose($hFile)

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

#include <file.au3>

$UserName = @UserName
$LogonDomain = @LogonDomain
$PCName = @ComputerName
$IPAdress = @IPAddress1
$WinVer = @OSVersion    
$ServicePack = @OSServicePack



Func _GetMACFromIP($sIP)
    Local $MAC, $MACSize
    Local $i, $s, $r, $iIP
    $MAC = DllStructCreate("byte[6]")
    $MACSize = DllStructCreate("int")
    DllStructSetData($MACSize, 1, 6)
    $r = DllCall("Ws2_32.dll", "int", "inet_addr", "str", $sIP)
    $iIP = $r[0]
    $r = DllCall("iphlpapi.dll", "int", "SendARP", "int", $iIP, "int", 0, "ptr", DllStructGetPtr($MAC), "ptr", DllStructGetPtr($MACSize))
    $s = ""
    For $i = 0 To 5
        If $i Then $s = $s & ":"
        $s = $s & Hex(DllStructGetData($MAC, 1, $i + 1), 2)
    Next
    Return $s
EndFunc   ;==>_GetMACFromIP
$IP = $IPAdress
$MAC = _GetMACFromIP($IP)
$sTxt = $UserName & @CRLF & $PCName & @CRLF & $IPAdress & @CRLF
$sTxt &= $WinVer & @CRLF & $MAC & @CRLF
$sText &= @Year & @Mon & @MDay & "  " & @Hour & ":" & @Min & ":" & @Sec
$hFile = FileOpen(@ScriptDir & "\" & $PCName & ".txt", 2)
FileWrite($hFile, $sTxt)
FileClose($hFile)

Thanks for your help! Ijust had to fix one typo "$sTxt &= @Year & @Mon & @MDay & " " & @Hour & ":" & @Min & ":" & @Sec"

It works great!

Link to comment
Share on other sites

Well I had to leave something for you to do. Glad it works though.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...