Results 1 to 6 of 6

Thread: API in VBS?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Home
    Posts
    85

    API in VBS?

    Is there any way to use Win32 API Functions in VbScript?

    Just curious.

  2. #2
    Junior Member Alucard's Avatar
    Join Date
    Apr 2007
    Posts
    27

    Re: API in VBS?

    No you can't as far as i am aware.

  3. #3
    Member
    Join Date
    Sep 2005
    Posts
    49

    Re: API in VBS?

    Actuall you can create the object using it's ref name...ie Scripting.FilesystemObject = some dll... same applies for most dlls

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Home
    Posts
    85

    Re: API in VBS?

    Could you give an example of doing that, with a function. Just anything as an example, like showwindow, or shellexecute.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    Home
    Posts
    85

    Re: API in VBS?

    *Bump*

  6. #6
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    Re: API in VBS?

    Function NameFromPing(sIP)
    Set Cmd = CreateObject("WScript.Shell")._
    Exec("ping -a -n 1 -w 1 " & sIP)
    NameFromPing = Split(Cmd.StdOut.ReadAll," ")(1)
    End Function


    Function NameFromTrace(sIP)
    Set Cmd = CreateObject("WScript.Shell")._
    Exec("tracert -h 1 -w 1 " & sIP)
    NameFromTrace = Split(Cmd.StdOut.ReadAll," ")(3)
    End Function


    Function nslook(sTargetDomain)
    cmdline = "cmd /c nslookup -type=mx " & sTargetDomain
    Set Cmd = CreateObject("WScript.Shell").Exec(cmdline)
    nslook = Cmd.StdOut.ReadAll
    End Function


    Function psSID(sHost)
    psSID = split(CreateObject("WScript.Shell").Exec( _
    "%COMSPEC% /C psgetsid " & sHost).StdOut.ReadAll, vbCrLf)(6)
    If Instr(psSID,"No mapping") Then psSID = ""
    End Function


    Function QBasic(filarg)
    ' Wrapper for running QuickBasic programs
    ' QB File MUST have last line: SYSTEM
    Dim Sh, FSO, fOut, OutF, Cmd
    Set Sh = createobject("WScript.Shell")
    Set FSO = createobject("Scripting.FileSystemObject")
    fOut = FSO.GetTempName
    Cmd = "%COMSPEC% /c qb /run " & filarg _
    & " 2>NUL 1>" & fOut
    wscript.echo Cmd
    Wscript.Quit
    Sh.Run Cmd, 0, True
    If FSO.FileExists(fOut) Then
    If FSO.GetFile(fOut).Size>0 Then
    Set OutF = FSO.OpenTextFile(fOut)
    QBasic = OutF.Readall
    OutF.Close
    End If
    FSO.DeleteFile(fOut)
    End If
    End Function

    sub RegisterControl(strControlName)
    set objShell = CreateObject("WScript.Shell")
    sCMD = "regsvr32 /s " & strControlName
    rtn = objShell.run(sCMD, 0, true)
    wscript.echo strControlName & " " & rtn
    end sub


    Sub SetServiceState(Svc, State)
    ' Uses simple shell commands
    ' state should be: pause, resume, stop, start
    CreateObject("WScript.Shell").Run("net " & state & " " & Svc),0,True
    End Sub


    Sub SetVar_Volatile(VarName,VarValue)
    set shell = createobject("wscript.shell")
    set envVolatile = shell.environment("volatile")
    envVolatile(VarName) = VarValue
    End Sub


    Sub UnRegisterControl(strControlName)
    Set Sh= CreateObject("WScript.Shell")
    sCMD = "regsvr32 /s /u" & strControlName
    rtn = Sh.Run(sCMD, 0, True)
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width