Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 file_name = "\autoexec.cfg" file_path = "d:\games\HL\cstrike" user_pwd = "Pa$$w0rd" file_path = ShowDialog() Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(file_path & file_name) Then ' file exists - check i pwd exists inside tmp = FindPwd (file_path & file_name) if tmp = "" then ' pwd does not exist - so ask and put user_pwd = GetPwd(user_pwd) if user_pwd <> "" then ' append to end of file' Set objFile = objFSO.OpenTextFile(file_path & file_name, ForAppending) objFile.Writeline objFile.Writeline "setinfo ""_pw"" """& user_pwd &"""" objFile.Close end if else 'pwd exists, ask user if he want to change existing pwd' user_pwd = GetPwd(tmp) if user_pwd <> "" then ' Read all file' Set objFile = objFSO.OpenTextFile(file_path & file_name, ForReading) tmp = objFile.ReadAll objFile.Close ' Search line-by-line to replace _pw tmp = Split(tmp, vbCrLf) Set objFile = objFSO.OpenTextFile(file_path & file_name, ForWriting) For Each line in tmp If InStr(line, "_pw") Then objFile.Writeline "setinfo ""_pw"" """& user_pwd &"""" else objFile.Writeline line End If Next objFile.Close end if end if Else user_pwd = GetPwd(user_pwd) if user_pwd <> "" then Set objFile = objFSO.CreateTextFile(file_path & file_name, forWriting) objFile.Writeline "setinfo ""_pw"" """& user_pwd &"""" & vbCrLf objFile.Close end if End If ' ---------------------- ' User pwd input ' ---------------------- function GetPwd(pwd) GetPwd = InputBox("Введите пожалуйста пароль:", "Pwd changer by Falcon (c)TFSoft", pwd) end function ' ---------------------- ' Find pwd ' ---------------------- function FindPwd(path) Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(path, forReading) tmp = objFile.ReadAll tmp = Split(tmp, vbCrLf) For Each line in tmp If InStr(line, "_pw") Then arrText = Split(line, " ") FindPwd = Replace(arrText(2), """", "") End If Next objFile.Close end function ' ---------------------- ' ShowDialog to select folder ' ---------------------- function ShowDialog() Const MY_COMPUTER = &H11& Const WINDOW_HANDLE = 0 Const OPTIONS = 0 Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.Namespace(MY_COMPUTER) Set objFolderItem = objFolder.Self strPath = objFolderItem.Path Set objShell = CreateObject("Shell.Application") Set objFolder = objShell.BrowseForFolder _ (WINDOW_HANDLE, "Найдите папку cstrike, которая находиться в папке с Half-Life, к примеру " & file_path, OPTIONS, strPath) If (objFolder Is Nothing) Then Wscript.Quit End If if InStr(objFolder, "cstrike") = 0 then Wscript.echo "Этот путь не содержить папку cstrike" Wscript.Quit end if Set objFolderItem = objFolder.Self objPath = objFolderItem.Path ShowDialog = objPath end function