Sign in to follow this  
Followers 0
Dalex

_RunDos won't write variable

11 posts in this topic

What am I doing wrong?

I want this to write the current logged on user to the Computer description field. it works if I include a name inside the quotes but not it won't write the variable.

I have included the message box just to show that it is the correct syntax to be written to console.

#include <Process.au3>
Dim $sComputerDesc = "net config server /srvcomment:" & @UserName
MsgBox(0,"", $sComputerDesc)
_RunDOS ( $sComputerDesc)

[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Check the returncode and @error after _RunDOS.

#include <Process.au3>
Dim $sComputerDesc = "net config server /srvcomment:" & @UserName
MsgBox(0,"", $sComputerDesc)
$iReturnCode = _RunDOS ( $sComputerDesc)
MsgBox(0, "After _RunDOS", "Returncode: " & $iReturnCode & ", @error: " & @error)

What do you get?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I get this:

Returncode:1, @error:0

What does that mean? :graduated:


[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
Share on other sites

Have you tried it using just the Run command?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Not sure what you mean?

like this?

Dim $sComputerDesc = "net config server /srvcomment:" & @UserName
MsgBox(0,"", $sComputerDesc)
$iReturnCode = Run( $sComputerDesc)
MsgBox(0, "After _RunDOS", "Returncode: " & $iReturnCode & ", @error: " & @error)

[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
Share on other sites

Yes, run it without calling @Comspec first.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks, I will try it when I get back home.


[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

If this is what you mean, I don't understand how that could work.

Run ("net config server /srvcomment:" & @UserName)

This doesn't work either.

_RunDOS ( "net config server /srvcomment:" & @UserName)
Edited by Dalex

[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

ok, I figured it out......You knew the answer the whole time didn't you?

The command requires the desired value to be enclosed in quotes. I just had to double quote around the macro like this:

#include <Process.au3>
Dim $sComputerDesc = "net config server /srvcomment:" &  '"'& @UserName & '"'
_RunDOS($sComputerDesc)

Hey Brewman, RDWHAHB, bet you know what that means too huh?

Edited by Dalex

[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
Share on other sites

I didn't realize that it would need the quotes around the user name, because they don't usually have spaces in them. Unless the command for the comment needs the quotes, I would never have guessed it.

p.s.: I'd have a homebrew, if the wife would let me make it :graduated:


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Oh man I hate to hear that. If I could I would send you a couple. Where are you New Hampshire ?

Thanks for the help, I have found that some times it takes someone on the outside looking in to help me break out of the box that is my simple mind.


[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

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

  • Similar Content

    • DavidLago
      By DavidLago
      Well, I've reached the loop point. I really don't know what to think or to do anymore

      Let me try to explain. This script I'll post below export the output of the the command "openfiles" on cmd, and it has an option to filter the logs to something that the analyst want to check in particular. For example. I wanna know how many guys are accessing the folder "X:folder1" or how many folders is the computer "Computer342312" accessing through the DFS.


      ;---------------------------------------------------------------INCLUDES-------------------------------------------------------------------------------- #include <Process.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <INet.au3> #include <Date.au3> ;------------------------------------------------------------EXPORT-FOLDER-------------------------------------------------------------------------------- If Not FileExists(@ScriptDir & "Export") Then DirCreate(@ScriptDir & "Export") EndIf ;------------------------------------------------------------ WHILE LOOP -------------------------------------------------------------------------------- Global $iNow = _NowCalc() Global $TimeOut = False While $TimeOut = False ;---------------------------------------------------------VARIABLES----------------------------------------------------------------------------------- Global $Date = @YEAR & "-" & @MON & "-" & @MDAY Global $Hour = @HOUR & "-" & @MIN & "--" Global $FullDate = $Date & "_" & $Hour Global $ReportDir = @ScriptDir & "Export" ;----------------------------------------------------------INI_READ----------------------------------------------------------------------------------- Global $TimeFreq = IniRead("Config.ini", "Time", "Frequency", "60") Global $TimeDur = IniRead("Config.ini", "Time", "Duration", "24") Global $ReportOut = $FullDate & "_" & IniRead("Config.ini", "ReportOut", "ReportOut", "Report") Global $FilterExt = IniRead("Config.ini", "FilterExt", "FilterExt", "N") Global $FileExt = '"' & IniRead("Config.ini", "FileExt", "FileExt", "exe") & '"' Global $FormatOut = IniRead("Config.ini", "FormatOut", "FormatOut", "Table") ;-------------------------------------------------------ADVANCED VARIABLES----------------------------------------------------------------------------- Global $CommandCombo, $CommandFinal, $iDiff, $FreqDurMath $iTimeFreq = $TimeFreq * 60000 ; Turn to miliseconds $iTimeDur = $TimeDur ; Turn to minutes $FreqDurMath = ($TimeDur * 60) / $TimeFreq ;-------------------------------------------------------ERROR-TREATMENT--------------------------------------------------------------------------------- If $iTimeFreq < 900000 Then MsgBox(4112, "Error", 'The parameter "FREQUENCY" at the config.ini file is set to a number below 15. 15 minutes is the minumum threshold', 5) Exit EndIf If $FreqDurMath < 1 Then If MsgBox(4116, "Error", 'The parameters "FREQUENCY" and "DURATION" at the config.ini file is set to a number which prevents it to loop more than once. Do you want to continue?', 10) = 7 Then Exit EndIf ;----------------------------------------------------------COMMAND BREED I------------------------------------------------------------------------------- Global $QueryCommand = "/query " & "/FO " & $FormatOut & " /V " & "/nh " Global $FindCommand = "| find /I " & $FileExt Global $ExportCommand = " > " & '"' & $ReportDir & $ReportOut & ".log" & '"' ;----------------------------------------------------------COMMAND BREED II------------------------------------------------------------------------------ If $FilterExt = "Y" Then $CommandCombo = $QueryCommand & $FindCommand & $ExportCommand Else $CommandCombo = $QueryCommand & $ExportCommand EndIf $CommandFinal = "openfiles " & $CommandCombo ;-------------------------------------------------------------OPTIONS----------------------------------------------------------------------------------- If $FilterExt = "Y" Then If $FileExt <> "" Then TrayTip("Message from the " & @ScriptName & " Script: ", 'The command "' & $CommandFinal & '" is running in this server. Options enabled are the following:' & @CRLF & @CRLF & "Filter: " & '"' & $FilterExt & '"' & @CRLF & "Ext/String: " & $FileExt & @CRLF, 1, 1) FileWriteLine(@ScriptDir & "" & "CommandOut.txt", $CommandFinal) Else TrayTip("Message from the " & @ScriptName & " Script: ", 'The command "' & $CommandFinal & '" is running in this server.', 1, 1) FileWriteLine(@ScriptDir & "" & "CommandOut.txt", $CommandFinal) EndIf EndIf ;-----------------------------------------------------------MAIN COMMAND--------------------------------------------------------------------------------- ;--------MAIN COMMAND----------------------------------- _RunDOS($CommandFinal) ;--------MAIN COMMAND----------------------------------- $iDiff = _DateDiff('h', $iNow, _NowCalc()) Sleep($iTimeFreq) ;Frequency, If $iDiff > $iTimeDur Then $TimeOut = True EndIf If $TimeOut = True Then Exit WEnd ;==> While from line 20
      The ini File is the following:


      [Time] # What frequency? (Minutes [minimum: 15 min) / How long? (Hours [Minimum: 1H) Frequency = 15 Duration = 1 [FilterExt] # GREP Extension/String? ( Y, N) FilterExt = Y [FileExt] # What's the extension or string combo to be matched? (.exe; .doc; .csv; Solidworks; Report, etc. (default: line commented by #) FileExt = C:Sharing [ReportOut] # LogFile Sufix ReportOut = Report [FormatOut] # LogFile Format: CSV or Table. (default: table) FormatOut = CSV

      So, It wasn't working. I tried to debug every line and it still didn't find anything wrong, so I created a filewriteline that writes down the SAME command that _RunDOS is running before it runs it. And if you copy and paste this command on the cmd line, it works, but the same command within _RunDOS generates a logfile with 0kb.

      To test it you must create a sharing in your computer, and access a file like a .doc or .xls from another computer, then use the filter on the .ini file.

      Check the the file in the EXPORT folder, it has 0kb. Delete it, and run on cmd the same exported command at scriptdir file "CommandOut.txt" and now, explain why it doesn't work.

      It makes 0 sense.
    • DavidLago
      By DavidLago
      Hello, fellows.

      I recently gave fingerbirth to a script that reports out the current files, and users opening those files currently. Also provides a filter for strings/extensions.

      Suggestions and improvements are welcome.




      #cs ---------------------------Script Start------------------------------------- | Author: DavidLago (Hellfrost) | Script Function: Reports out a logfile containing openfiles within a (file)server, configured under an ini file #ce ---------------------------------------------------------------------------- ;---------------------------------------------------------------INCLUDES-------------------------------------------------------------------------------- #include <Process.au3> #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> #include <Date.au3> ;------------------------------------------------------------EXPORT-FOLDER-------------------------------------------------------------------------------- If Not FileExists(@ScriptDir & "\Export") Then DirCreate(@ScriptDir & "\Export") EndIf ;------------------------------------------------------------ WHILE LOOP -------------------------------------------------------------------------------- Global $iNow = _NowCalc() Global $TimeOut = False While $TimeOut = False ;---------------------------------------------------------VARIABLES----------------------------------------------------------------------------------- Global $Date = @MON & "-" & @MDAY & "-" & @YEAR Global $Hour = @HOUR & "'" & @MIN & "''" Global $FullDate = $Date & "_" & $Hour Global $ReportDir = @ScriptDir & "\Export\" ;----------------------------------------------------------INI_READ----------------------------------------------------------------------------------- Global $MailFrom = IniRead("Config.ini", "Mail", "MailFrom", "Script_OpenFiles@AutoITScripting.net") Global $Mailto = IniRead("Config.ini", "Mail", "Mailto", "") Global $MailSubj = IniRead("Config.ini", "Mail", "MailSubj", "") Global $MailBody = IniRead("Config.ini", "Mail", "MailBody", "") Global $TimeFreq = IniRead("Config.ini", "Time", "Frequency", "60") Global $TimeDur = IniRead("Config.ini", "Time", "Duration", "24") Global $ReportOut = $FullDate & "_" & IniRead("Config.ini", "ReportOut", "ReportOut", "Report") Global $FilterExt = IniRead("Config.ini", "FilterExt", "FilterExt", "N") Global $FileExt = '"' & IniRead("Config.ini", "FileExt", "FileExt", "exe") & '"' Global $FormatOut = IniRead("Config.ini", "FormatOut", "FormatOut", "Table") ;-------------------------------------------------------MATH VARIABLES---------------------------------------------------------------------------------- Global $CommandCombo, $CommandFinal, $iDiff, $FreqDurMath $iTimeFreq = $TimeFreq * 60000 ; Turn to miliseconds $iTimeDur = $TimeDur ; Turn to minutes $FreqDurMath = ($TimeDur * 60) / $TimeFreq ;-------------------------------------------------------ERROR-TREATMENT--------------------------------------------------------------------------------- If $iTimeFreq < 900000 Then MsgBox(4112, "Error", 'The parameter "FREQUENCY" at the config.ini file is set to a number below 15. 15 minutes is the minumum threshold', 5) $MailBody = 'The Script "' & @ScriptName & '" is reporting the following error: The parameter "FREQUENCY" at the config.ini file is set to a number below 15. ' & @CRLF & '15 minutes is the minumum threshold' SendMail($MailBody) Exit EndIf If $FreqDurMath < 1 Then $MailBody = 'The Script "' & @ScriptName & '" The parameters "FREQUENCY" and "DURATION" at the config.ini file is set to a number which prevents it to loop more than once. Do you want to continue?' SendMail($MailBody) If MsgBox(4116, "Error", 'The parameters "FREQUENCY" and "DURATION" at the config.ini file is set to a number which prevents it to loop more than once. Do you want to continue?', 10) = 7 Then Exit EndIf ;----------------------------------------------------------COMMAND BREED I------------------------------------------------------------------------------- Global $QueryCommand = "/query " & "/FO " & $FormatOut & " /V " & "/nh " Global $FindCommand = "| find /I " & $FileExt Global $ExportCommand = " > " & '"' & $ReportDir & $ReportOut & ".log" & '"' If $FilterExt = "Y" Then $CommandCombo = $QueryCommand & $FindCommand & $ExportCommand Else $CommandCombo = $QueryCommand & $ExportCommand EndIf $CommandFinal = "openfiles " & $CommandCombo ;-------------------------------------------------------------OPTIONS----------------------------------------------------------------------------------- If $FilterExt = "Y" Then If $FileExt <> "" Then TrayTip("Message from the " & @ScriptName & " Script: ", 'The command "' & $CommandFinal & '" is running in this server. Options enabled are the following:' & @CRLF & @CRLF & "Filter: " & '"' & $FilterExt & '"' & @CRLF & "Ext/String: " & $FileExt & @CRLF, 1, 1) Else TrayTip("Message from the " & @ScriptName & " Script: ", 'The command "' & $CommandFinal & '" is running in this server.', 1, 1) EndIf EndIf ;--------MAIN COMMAND-----------------------------------################## _RunDOS($CommandFinal) ;--------MAIN COMMAND-----------------------------------################## $iDiff = _DateDiff('h', $iNow, _NowCalc()) Sleep($iTimeFreq) ; <-Frequency If $iDiff > $iTimeDur Then ; <-- Is time through? $TimeOut = True $MailBody = 'The script "' & @ScriptName & '", which was running at the server "' & @ComputerName & '", generated the requested logs successfully. Please, contact your Domain administrator to claim them' SendMail($MailBody) EndIf WEnd ;==> While from line 18 ;------------------------Function to send e-mail-------------------------------------------------------------------------------------------------------------- Func SendMail($MailBody) $objEmail = ObjCreate("CDO.Message") $objEmail.From = $MailFrom $objEmail.To = $Mailto $objEmail.Subject = $MailSubj $objEmail.Textbody = $MailBody $objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _ "mail.domain.net" ; <----------------------------------------- Insert your mailserver here $objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 $objEmail.Configuration.Fields.Update $objEmail.Send EndFunc ;==>SendMail



      Contents of the config.ini file:



      #--------------------------------------------------------------------# # Config. ini # #--------------------------------------------------------------------# #--------------------------------------------------------------------# # OPENFILES REPORT: # Reports out a logfile containing openfiles within a server #--------------------------------------------------------------------# [Time] # What frequency? (Minutes [minimum: 15 min) / How long? (Hours [Minimum: 1H) Frequency = 15 Duration = 1 [FilterExt] # GREP Extension/String? ( Y, N) FilterExt = Y [FileExt] # What's the extension or string combo to be matched? (.exe; .doc; .csv; Solidworks; Report, etc. (default: line commented by #) FileExt = doc [ReportOut] # LogFile Sufix ReportOut = Report [FormatOut] # LogFile Format: CSV or Table. (default: table) FormatOut = CSV [Mail] MailFrom = Script_OpenFiles@AutoITScripts.com Mailto = hellfrost@hellfrost.info MailSubj = OpenFiles Alert Example MailBody = This message is an alert.

      It might be useful for a Domain admin someday.