| 1. |
Solve : Automatically editing a text fiel using a batch file? |
|
Answer» My co-worker and I end up editing a text file every time we image a Sales PC. It is not easy and we frequently make mistakes. There are only 5 variables but 4 are used multiple times and it would be nice if we could come up with a way of using batch file (or something similar) that we could just type the 5 variables and let it insert them in the correct places. I have PLAYED around some and am not having any luck. Any help would be greatly appreciated.post an example of the text file showing the variables and where they go, editing anything confidential if you need to. post an example of the text file showing the variables and where they go, editing anything confidential if you need to. I have replaced the ACTUAL terms with the variable placeholders (%1, %2, etc.). Quote use CRMBasehere's a vbscript, if you are able to use it Code: [Select]Set wshArgs = WScript.Arguments var1=wshArgs(0) var2=wshArgs(1) var3=wshArgs(2) var4=wshArgs(3) var5=wshArgs(4) Set objFSO=CreateObject("Scripting.FileSystemObject") s="use CRMBase" & vbCrLf & _ "delete from au_st_sys_user" & vbCrLf & _ "delete from au_system_user" & vbCrLf & _ "delete from au_employee where emp_code = '" & var1 & "'" & vbCrLf & _ "insert into au_employee ( emp_code, first_name, last_name, " & _ "create_emp, last_mdfy_emp, row_id, rec_mdfy_ind, rec_del_ind ) values ( '" & var1 & _ "', '" & var2 & "', '" & var3 & "', 'aurum', 'aurum', 2, 'N', 'N' )" & vbCrLf & _ "insert into au_user_class ( class_code, rec_del_ind ) values ( 'AurumSales', 'N' )" & vbCrLf & _ "insert into au_system_user ( emp_code, login, pwd, create_emp, " & _ "last_mdfy_emp, row_id, rec_mdfy_ind, rec_del_ind, class_code ) values ( '" & _ var1 & "', '" & var1 & "', '8_49_76_69_71_72_72_7F_30_2C_A_17_1A_6_ 5_14', 'aurum', 'aurum', 2, 'N', 'N', 'AurumSales' )" & vbCrLf & _ "update au_system_user set exp_date = CURRENT_TIMESTAMP" & vbCrLf & _ "update au_system_user set exp_date = exp_date + 60" & vbCrLf & _ "insert into au_st_sys_user ( st_id, emp_code, st_emp_code, auth_key, authority_flag, " & _ "enable_esd_ind, create_emp, last_mdfy_emp, row_id, rec_mdfy_ind, rec_del_ind ) values ( " & _ var4 & ", '" & var1 & "', '" & var1 & "-R', '" & var5 & "', 'TT', 'Y', 'aurum', 'aurum', 2, 'N', 'N' )" & vbCrLf & _ "delete from au_system_id" & vbCrLf & _ "insert into au_system_id ( emp_code, system_id, auth_key, class_code ) values ( '" & _ var1 & "', '" & var4 & "', '" & var5 & "', 'AurumSales')" & vbCrLf &_ "go" Set objOutFile = objFSO.CreateTextFile("c:\outfile.txt",True) objOutFile.Write(s) objOutFile.Close Set objOutFile=Nothing usage: on command PROMPT type : cscript /nologo myscript.vbs var1 var2 var3 var4 var5Worked like a champ -- Thanks. |
|