Sign in to follow this  
Followers 0
jkuzo

Output txt file with computer name

17 posts in this topic

I found this script to extract all programs installed on a machine and then put that information into a text file. How can I edit this so that rather than creating regtext.txt file it would create a %computername%.txt file. This way when i pull all those txt files they would all have unique names?

#include <File.au3>

$file = "c:\testreg.txt"

If Not FileExists($file) Then

_FileCreate("c:\testreg.txt")

EndIf

FileOpen($file, 2) ;erases file for new contents

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0

While 1

$i += 1

$var = RegEnumKey($regItem, $i)

If @error Then ExitLoop

$varr = RegRead($regItem & $var & "\", "DisplayName")

FileWriteLine($file, 'Key Name: ' & $var & @CRLF)

WEnd

FileClose($file)

Share this post


Link to post
Share on other sites



#include <File.au3>
$file = "c:\"&@ComputerName&".txt"
If Not FileExists($file) Then _FileCreate("c:\testreg.txt")
FileOpen($file, 2) ;erases file for new contents
$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0
While 1
    $i += 1
    $var = RegEnumKey($regItem, $i)
    If @error Then ExitLoop
    $varr = RegRead($regItem & $var & "\", "DisplayName")
    FileWriteLine($file, 'Key Name: ' & $var & @CRLF)
WEnd
FileClose($file)

Share this post


Link to post
Share on other sites

#include <File.au3>
$file = "c:\"&@ComputerName&".txt"
If Not FileExists($file) Then _FileCreate("c:\testreg.txt")
FileOpen($file, 2) ;erases file for new contents
$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0
While 1
    $i += 1
    $var = RegEnumKey($regItem, $i)
    If @error Then ExitLoop
    $varr = RegRead($regItem & $var & "\", "DisplayName")
    FileWriteLine($file, 'Key Name: ' & $var & @CRLF)
WEnd
FileClose($file)
Thanks... Now another question.. What if I then wanted to look for a particular piece of software, such as, adobe acrobat professional? If it exists, then open a designated .txt file on the network and add "&@computername&" to that txt file and then save. Basically querying computers based on a piece of software and in return getting the computer name added to a list included in a txt file? Thanks a bunch, just getting used to all this autoit stuff. Def see some nice posibilities with it.

Share this post


Link to post
Share on other sites

#include <File.au3>
$file = "c:\"&@ComputerName&".txt"
If Not FileExists($file) Then _FileCreate("c:\testreg.txt")
FileOpen($file, 2) ;erases file for new contents
$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0
While 1
    $i += 1
    $var = RegEnumKey($regItem, $i)
    If @error Then ExitLoop
    $varr = RegRead($regItem & $var & "\", "DisplayName")
    if $varr="adobe acrobat professional" then FileWriteLine($NetworkFilePath,@ComputerName) ;Of course here 'adobe acrobat professional' and $NetworkFilePath have to be changed to suit your needs.
    FileWriteLine($file, 'Key Name: ' & $var & @CRLF)
WEnd
FileClose($file)

Share this post


Link to post
Share on other sites

#include <File.au3>
$file = "c:\"&@ComputerName&".txt"
If Not FileExists($file) Then _FileCreate("c:\testreg.txt")
FileOpen($file, 2) ;erases file for new contents
$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0
While 1
    $i += 1
    $var = RegEnumKey($regItem, $i)
    If @error Then ExitLoop
    $varr = RegRead($regItem & $var & "\", "DisplayName")
    if $varr="adobe acrobat professional" then FileWriteLine($NetworkFilePath,@ComputerName) ;Of course here 'adobe acrobat professional' and $NetworkFilePath have to be changed to suit your needs.
    FileWriteLine($file, 'Key Name: ' & $var & @CRLF)
WEnd
FileClose($file)

Thanks, what am i missing here???

#include <File.au3>

$file = "c:\"&@ComputerName&".txt"

If Not FileExists($file) Then _FileCreate("c:\testreg.txt")

FileOpen($file, 2) ;erases file for new contents

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0

While 1

$i += 1

$var = RegEnumKey($regItem, $i)

If @error Then ExitLoop

$varr = RegRead($regItem & $var & "\", "DisplayName")

if $varr="Adobe Acrobat 7.0 Professional - V" then FileWriteLine( \\adm-util\software\software.txt,@ComputerName) ;Of course here 'adobe acrobat professional' and $NetworkFilePath have to be changed to suit your needs.

FileWriteLine($file, 'Key Name: ' & $var & @CRLF)

WEnd

FileClose($file)

Getting this error:

>"C:\Program Files\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\jkuzo.QCSD\Documents\testsoftware.au3"

C:\Users\jkuzo.QCSD\Documents\testsoftware.au3 (13) : ==> Badly formated variable or macro.:

if $varr="Adobe Acrobat 7.0 Professional - V" then FileWriteLine( $\\adm-util\software\software.txt,@ComputerName)

if $varr="Adobe Acrobat 7.0 Professional - V" then FileWriteLine( ^ ERROR

>Exit code: 1 Time: 0.200

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#include <File.au3>
$file = "c:\"&@ComputerName&".txt"
If Not FileExists($file) Then _FileCreate("c:\testreg.txt")
FileOpen($file, 2) ;erases file for new contents
$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0
While 1
$i += 1
$var = RegEnumKey($regItem, $i)
If @error Then ExitLoop
$varr = RegRead($regItem & $var & "\", "DisplayName")
if $varr="Adobe Acrobat 7.0 Professional - V" then FileWriteLine("\\adm-util\software\software.txt",@ComputerName) 
FileWriteLine($file, 'Key Name: ' & $var & @CRLF)
WEnd
FileClose($file)

Edited by evilertoaster

Share this post


Link to post
Share on other sites

#include <File.au3>
$file = "c:\"&@ComputerName&".txt"
If Not FileExists($file) Then _FileCreate("c:\testreg.txt")
FileOpen($file, 2) ;erases file for new contents
$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0
While 1
$i += 1
$var = RegEnumKey($regItem, $i)
If @error Then ExitLoop
$varr = RegRead($regItem & $var & "\", "DisplayName")
if $varr="Adobe Acrobat 7.0 Professional - V" then FileWriteLine("\\adm-util\software\software.txt",@ComputerName) 
FileWriteLine($file, 'Key Name: ' & $var & @CRLF)
WEnd
FileClose($file)
Didn't work. Tested on my machine looking for autoit and it didn't write anything to the software.txt file. any ideas?

#include <File.au3>

$file = "c:\"&@ComputerName&".txt"

If Not FileExists($file) Then _FileCreate("c:\testreg.txt")

FileOpen($file, 2) ;erases file for new contents

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0

While 1

$i += 1

$var = RegEnumKey($regItem, $i)

If @error Then ExitLoop

$varr = RegRead($regItem & $var & "\", "DisplayName")

if $varr="AutoItv3" then FileWriteLine("\\adm-util\software\software.txt",@ComputerName) ;Of course here 'adobe acrobat professional' and $NetworkFilePath have to be changed to suit your needs.

FileWriteLine($file, 'Key Name: ' & $var & @CRLF)

WEnd

FileClose($file)

I'm searching by key name though not display name? Not sure where the problem lies.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

#include <File.au3>
$file = "c:\"&@ComputerName&".txt"
If Not FileExists($file) Then _FileCreate("c:\testreg.txt")
FileOpen($file, 2) ;erases file for new contents
$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0
While 1
$i += 1
$var = RegEnumKey($regItem, $i)
If @error Then ExitLoop
$varr = RegRead($regItem & $var & "\", "DisplayName")
if $varr="Adobe Acrobat 7.0 Professional - V" then 
    MsgBox(0,"Adobe was found", "Writing to text file")
    $Result=FileWriteLine("\\adm-util\software\software.txt",@ComputerName)
    if $Result= 0 then MsgBox(0,"Error","The File could not be written to, check that the path and permissions are correct")
EndIf
FileWriteLine($file, 'Key Name: ' & $var & @CRLF)
WEnd
FileClose($file)

This will make a message box appear if it ever find Adobe with the name you put in. If the message box doesn't come up it is becuase your name for adobe is wrong or it actually isnt installed(the check runs agianst the display name not the key name). I also added a check to see if the file write executes correctly.

Edited by evilertoaster

Share this post


Link to post
Share on other sites

#include <File.au3>
$file = "c:\"&@ComputerName&".txt"
If Not FileExists($file) Then _FileCreate("c:\testreg.txt")
FileOpen($file, 2) ;erases file for new contents
$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0
While 1
$i += 1
$var = RegEnumKey($regItem, $i)
If @error Then ExitLoop
$varr = RegRead($regItem & $var & "\", "DisplayName")
if $varr="Adobe Acrobat 7.0 Professional - V" then 
    MsgBox(0,"Adobe was found", "Writing to text file")
    $Result=FileWriteLine("\\adm-util\software\software.txt",@ComputerName)
    if $Result= 0 then MsgBox(0,"Error","The File could not be written to, check that the path and permissions are correct")
EndIf
FileWriteLine($file, 'Key Name: ' & $var & @CRLF)
WEnd
FileClose($file)

This will make a message box appear if it ever find Adobe with the name you put in. If the message box doesn't come up it is becuase your name for adobe is wrong or it actually isnt installed(the check runs agianst the display name not the key name). I also added a check to see if the file write executes correctly.

So the following script works however it enters the computer name twice in the text file when it finds an occurance of the desired program. I can't seem to see or figure out why it would do this.

#include <File.au3>

$file = "c:\"&@ComputerName&".txt"

If Not FileExists($file) Then _FileCreate("c:\testreg.txt")

FileOpen($file, 2) ;erases file for new contents

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$i = 0

While 1

$i += 1

$var = RegEnumKey($regItem, $i)

If @error Then ExitLoop

$varr = RegRead($regItem & $var & "\", "DisplayName")

if $varr="Adobe Acrobat 7.0 Professional" then FileWriteLine("\\adm-util\software\software.txt",@ComputerName) ;Of course here 'adobe acrobat professional' and $NetworkFilePath have to be changed to suit your needs.

WEnd

FileClose($file)

Share this post


Link to post
Share on other sites

Odd thing is, is that its not every instance where the computer name gets entered twice. I did double check and compare registry keys and both registry's look identical between one that gets entered twice and one that gets entered only once. Not sure why this is happening. Is it possible to put in and if computername exists in the txt file to exit? Maybe you'll know why some are getting entered twice but i do not see any reason for this to be happing.

Share this post


Link to post
Share on other sites

Odd thing is, is that its not every instance where the computer name gets entered twice. I did double check and compare registry keys and both registry's look identical between one that gets entered twice and one that gets entered only once. Not sure why this is happening. Is it possible to put in and if computername exists in the txt file to exit? Maybe you'll know why some are getting entered twice but i do not see any reason for this to be happing.

Ok, so the problem with it coming up twice is because the display name actually occurs twice in the uninstall. There is a class entry that references it as well. What I would like to do is just search for a designated entry such as this

#include <File.au3>

$file = "c:\"&@ComputerName&".txt"

If Not FileExists($file) Then _FileCreate("c:\testreg.txt")

FileOpen($file, 2) ;erases file for new contents

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Adobe Acrobat 7.0 Professional - V"

$i = 0

While 1

$i += 1

$var = RegEnumKey($regItem, $i)

If @error Then ExitLoop

$varr = RegRead($regItem & $var & "\", "DisplayName")

if $varr="Adobe Acrobat 7.0 Professional" then FileWriteLine("\\adm-util\software\software.txt",@ComputerName) ;Of course here 'adobe acrobat professional' and $NetworkFilePath have to be changed to suit your needs.

WEnd

FileClose($file)

So if that if that adobe acrobat 7.0 Professional - V entry occurs in the uninstall directory of the registry to list the name in the txt file. As this is now, it does not work by simply changing the $regitem. I'm sure this has to do with the $var = RegEnumKey($regItem, $i), but i'm unsure how to resolve it.

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

You seem to be making the check harder than it needs to be:

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$Prog = "Adobe Acrobat 7.0 Professional"

RegRead($regItem & $Prog, "DisplayName")
If Not @error Then
    MsgBox(64, "Found", "Found " & $Prog & " on " & @ComputerName & ".")
Else
    MsgBox(16, "Not Found", "Did not find " & $Prog & " on " & @ComputerName & ".")
EndIf

What's with all the registry enumeration and looping stuff?

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You seem to be making the check harder than it needs to be:

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$Prog = "Adobe Acrobat 7.0 Professional"

RegRead($regItem & $Prog, "DisplayName")
If Not @error Then
    MsgBox(64, "Found", "Found " & $Prog & " on " & @ComputerName & ".")
Else
    MsgBox(16, "Not Found", "Did not find " & $Prog & " on " & @ComputerName & ".")
EndIf

What's with all the registry enumeration and looping stuff?

:)

I don't want msgboxs though as this will be something dropped on hundreds of computers. It should be unknown to the end user.

Share this post


Link to post
Share on other sites

I don't want msgboxs though as this will be something dropped on hundreds of computers. It should be unknown to the end user. Sorry i'm just learning..

What is wrong with the following??

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"

$Prog = "Adobe Acrobat 7.0 Professional - V"

RegRead($regItem & $Prog, "DisplayName")

If Not @error Then

exit

Else

FileWriteLine("\\adm-util\software\software.txt",@ComputerName)

FileClose($file)

EndIf

Share this post


Link to post
Share on other sites

What is wrong with the following??

Nothing. Note the 'Not' in the IF statement means it will only write to the file if the key DOES NOT exist. That may be what you intended. Just for brevity's sake, you don't have to FileOpen/FileClose for FileWriteLine(), so that line can be dropped:

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$Prog = "Adobe Acrobat 7.0 Professional - V"

RegRead($regItem & $Prog, "DisplayName")
If Not @error Then
    Exit
Else
    FileWriteLine("\\adm-util\software\software.txt", @ComputerName)
EndIf

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Nothing. Note the 'Not' in the IF statement means it will only write to the file if the key DOES NOT exist. That may be what you intended. Just for brevity's sake, you don't have to FileOpen/FileClose for FileWriteLine(), so that line can be dropped:

$regItem = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
$Prog = "Adobe Acrobat 7.0 Professional - V"

RegRead($regItem & $Prog, "DisplayName")
If Not @error Then
    Exit
Else
    FileWriteLine("\\adm-util\software\software.txt", @ComputerName)
EndIf

:)

I'm an idiot. That was my problem... Thanks, worked like a charm.

Share this post


Link to post
Share on other sites

I'm an idiot. That was my problem... Thanks, worked like a charm.

So, it may not have been what didn't not intend...?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
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
Sign in to follow this  
Followers 0