Jump to content

Script to get input from user ,check in csv file and read corresponding values and pass that value to cmd


MadhaN
 Share

Recommended Posts

4 hours ago, MadhaN said:

I checked in help file i cannot understand proper since i have no knowledge in scripting. 

Perhaps you should start getting some knowledge in scripting, or give up trying to script if you're unwilling or unable to learn how to. Otherwise, all you're going to do is get code you don't understand doing things you don't know, without doing anything to help yourself learn anything. We can teach you to fish, but if you're not going to pick up the pole and start fishing, you're going to find it extremely difficult to do any scripting on your own, or you could just keep begging people to barf up code for you.

Edited by BrewManNH

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

Link to comment
Share on other sites

11 minutes ago, Nine said:

Brew is in a bad mood.  Happens when full moon. 

Not at all, just sick of the whining and lack of effort shown. Not knowing how to script is an excuse to learn how to, not an excuse to do nothing and expect everyone else to do it for him.

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

Link to comment
Share on other sites

Hi all,

I made the below script which is working partially , its not searching exact match. I wanna Search Exact match . 

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>

$sFilePath="test.csv"
$aRetArray=$sFilePath

_FileReadToArray($sFilePath, $aRetArray, $FRTA_NOCOUNT, ",")
;_ArrayDisplay($aRetArray, "2D array - no count", Default, 8)

Local $sSearch = InputBox("_ArraySearch() demo", "String to find?")
If @error Then Exit

Local $sColumn = 0 ;InputBox("_ArraySearch() demo", "Column to search?")
If @error Then Exit
$sColumn = Int($sColumn)

Local $iIndex = _ArraySearch($aRetArray, $sSearch, 0, 0, 0, 1, 1, $sColumn)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Not Found", '"' & $sSearch & '" was not found on column ' & $sColumn & '.')
Else
    ;MsgBox($MB_SYSTEMMODAL, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ' on column ' & $sColumn & '.')
    MsgBox($MB_SYSTEMMODAL, "Found", '"' & $sSearch & '" was found in the array at position ' & $aRetArray[$iIndex][0] & $aRetArray[$iIndex][1] & '.')


EndIf

 

Link to comment
Share on other sites

Hai All,

Finally i created as i required. But one thing is i wanna hide the CMD , It should execute command .

 

Local $iIndex = _ArraySearch($aRetArray, $sSearch,  0, 0, 0, 2, 1,0) ; $sColumn)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Not Found", '"' & $sSearch & '" was not found on column ' & $sColumn & '.')
Else
    ;MsgBox($MB_SYSTEMMODAL, "Found", '"' & $sSearch & '" was found in the array at position ' & $iIndex & ' on column ' & $sColumn & '.')
   ; MsgBox($MB_SYSTEMMODAL, "Found", '"' & $sSearch & '" was found in the array at position ' & $aRetArray[$iIndex][0] & $aRetArray[$iIndex][1] & '.')
Run("C:\WINDOWS\system32\cmd.exe")
$win=WinWaitActive("C:\WINDOWS\system32\cmd.exe")
send('rdp /v:' & $aRetArray[$iIndex][2] &' '&'/u:'&$aRetArray[$iIndex][3] &' ' &'/p:'&$aRetArray[$iIndex][4] & "{ENTER}")

EndIf

 

Link to comment
Share on other sites

@MadhaN

If you did put the effort through which you ask for code in reading the Help file, you'd already finished your script.

In the Help file, about Run() function, there is specified:

To run DOS (console) commands, try Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE)    ; don't forget " " before "/c"

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

hI all, 

Now every thing working fine, But if i modify( increase the rows) my csv file its gives error.

Please help to resolve.

#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <Process.au3>

$sFilePath="ip.csv"
$aRetArray=$sFilePath

_FileReadToArray($sFilePath, $aRetArray, $FRTA_NOCOUNT, ",")
_ArrayDisplay($aRetArray, "2D array - no count", Default, 8)

image.png.4e47c4b0a4964111e40b5868cc276418.png

Link to comment
Share on other sites

Link to comment
Share on other sites

put that debug message after _FileReadToArray.

MsgBox (0,"",@error)

so we know what kind of error you got 

 

ps. stop begging it's getting irritating !!! 

Edited by Nine
Link to comment
Share on other sites

The error is pretty self-explanatory. You aren't giving the function an array, figure out why that is, and then go from there.

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

Link to comment
Share on other sites

@Nine , This is my final script working fine, when i use small file (30rows and 6 column  ), But i i user file with 1000+ rows am getting error.

; using a 2D array
#include <File.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <Process.au3>

Example()

Func Example()

$aRetArray = 0

 $sFilePath="123.csv"
 $aRetArray=$sFilePath


_FileReadToArray($sFilePath, $aRetArray, $FRTA_NOCOUNT, ",")
MsgBox (0,"",@error)
_ArrayDisplay($aRetArray, "2D array - no count", Default, 8)

Local $sSearch = InputBox(" RDP", "Enter ID:")
If @error Then Exit

Local $sColumn = 0 ;InputBox("_ArraySearch() demo", "Column to search?")
If @error Then Exit
$sColumn = Int($sColumn)

Local $iIndex = _ArraySearch($aRetArray, $sSearch,  0, 0, 0, 2, 1,0) ; $sColumn)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "ID Not Found", '"' & $sSearch & '" was not found on ID ' & $sColumn & '.')
Else

_RunDos('rdp /v:' & $aRetArray[$iIndex][2] &' '&'/u:'&$aRetArray[$iIndex][3] &' ' &'/p:'&$aRetArray[$iIndex][4] & "{ENTER}")


EndIf
 FileDelete($sFilePath)
 EndFunc   ;==>Example

 

Link to comment
Share on other sites

28 minutes ago, MadhaN said:

am getting "3"  error , it mean $aArray has too many dimensions,

No, it doesn't mean that. It means you have an inconsistent CSV file, there's more fields in some of the lines than in the rest. For example some of the lines may have 4 fields separated by commas, and in others there may be 3 fields separated by commas. The error messagebox is coming after the FRTA function.

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

Link to comment
Share on other sites

As Drew said, some lines have not enough or too much commas.  Take a careful look at your file, it's probably a mistake you have made when entering manually the lines.  A comma is very close to a dot :)

Edited by Nine
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

×
×
  • Create New...