dim objws,vbsPath,cmd
Set objws=WScript.CreateObject("wscript.shell")
Set fso = CreateObject("Scripting.FileSystemObject")

'程序当前路径
vpath = Left(WScript.ScriptFullName,Len(WScript.ScriptFullName)-Len(WScript.ScriptName)) 

port = GetProfileString("mysql","port",vpath + "config.ini")

'启动 MYSQL ,隐藏窗体,不等待MySQL结束
cmd = vpath & "bin\mysqladmin --port="& port &" --user=root --password= shutdown" 
WScript.Echo cmd
objws.Run cmd,0,True


Function MyTrim(mystring)
  Dim start,Endpos
  start=1
  for i=1 to Len(mystring)
    if Mid(mystring,i,1)=vbTab or Mid(mystring,i,1)=" " Then
      start=i+1
    else
      exit for
    end if
  next
  Endpos=Len(mystring)
  for i=Len(mystring) to 1 step -1
    if Mid(mystring,i,1)=vbTab or Mid(mystring,i,1)=" " Then
      Endpos=i-1
    else
      exit for
    end if
  next
  if (endpos-start+1)<0 then
    MyTrim=""
    Exit Function
  end if
  MyTrim=Mid(mystring,start,Endpos-start+1)
End Function

Function GetProfileString(section,key,filename)

  if fso.FileExists(filename) then
    Dim readini,bsection
    bsection=False
    
    Set readini = fso.OpenTextFile(filename,1)
    Do while not(readini.AtEndOfStream)
      Dim strini,trimstrini
      strini = readini.ReadLine
      trimstrini = MyTrim(strini)
      if Left(trimstrini,1)="[" and Right(Trimstrini,1)="]" then
        if StrComp(Trimstrini,"[" & MyTrim(section) & "]",1)=0 Then
          bsection=True
        else
          bsection =False
        end if
      Else
        if bsection then
          Dim poskey
          poskey = InStr(Trimstrini,"=")
          if posKey>0 then
            if StrComp(MyTrim(Left(Trimstrini,poskey-1)),MyTrim(key),1)=0 Then
              GetProfileString = MyTrim(Mid(Trimstrini,poskey+1))
              Exit Function
            end If  
          End if
        end if
      End if
    Loop
  End if
  
  GetProfileString = ""
End Function