Total Commander Forum Index Total Commander
Форум поддержки пользователей Total Commander
Сайты: Все о Total Commander | Totalcmd.net | Ghisler.com | RU.TCKB
 
 RulesRules   SearchSearch   FAQFAQ   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Single Post  Topic: Скрипт, меняющий значение строки в INI-файле 
Author Message
Batya



PostPosted: Tue May 11, 2010 14:09    Post subject: Reply with quote

Den_Klimov
Code:
'==========================================================
' Замена нескольких параметров в wincmd.ini и рестарт TC
'==========================================================
Option Explicit
Dim WSH, FSO, TCIniFile
Set WSH   = CreateObject("WScript.Shell")
Set FSO   = CreateObject("Scripting.FileSystemObject")
TCIniFile = WSH.ExpandEnvironmentStrings("%COMMANDER_INI%")

'Пример замены нескольких параметров
ChangeIni "DirBrackets=0"  , "DirBrackets=1"
ChangeIni "StartupScreen=0", "StartupScreen=1"

'Рестарт TC
RestartTotal

'Выход
Quit

Sub Quit
  Set WSH = Nothing
  Set FSO = Nothing
  WScript.Quit
End Sub

Sub ChangeIni(pStr1, pStr2)
  Dim Text
  Text = FSO.OpenTextFile(TCIniFile, 1).ReadAll
  Text = Replace(Text, pStr1, pStr2, 1, -1, 1)
  FSO.OpenTextFile(TCIniFile, 2).Write Text
End Sub

'(c) Volniy
Sub RestartTotal
  Dim TCS, TCexe, Timeout, QuitByTimeOut
  Set TCS = CreateObject("TCScript.Helper")
  TCexe = """" & TCS.TCPath & "\totalcmd.exe"""
  'Завершаем работу ТС
  TCS.SendCommand "cm_Exit", True

  'Ожидание завершения работы ТС
  Timeout = 3000 ' Сколько ждать выключения в мсек
  Do
     Timeout = Timeout - 100
     If Timeout < 0 Then QuitByTimeOut = True: Exit Do
     WScript.Sleep 100
  Loop While TCS.IsRunningTC

  'Запускаем новый экземпляр программы
  If Not QuitByTimeOut Then WSH.Run TCexe

  Set TCS = Nothing
End Sub


17.05.2010 - Исправлено. Убрано обращение к внешнему скрипту.
_________________
Нет, я не сплю. Я просто медленно моргаю.


Last edited by Batya on Mon May 17, 2010 09:30; edited 1 time in total
View user's profile Send private message


Powered by phpBB © 2001, 2005 phpBB Group