Jump to content

Recommended Posts

Posted

i made a little script for run a programs at my PC

when i try to run this script i get this error

Line 22 (File)

If (computername = "Zief") {

If (computername = "Zief") ^ERROR

Unable to parse line.

If (computername = "Zief") {

Run, C:\Program Files (x86)\TeamViewer\Version7\TeamViewer.exe

}

And Anyone can give me script for get pnpdeviceid?

like this script?

Func _getpnpdeviceid($drive, $fullid = 0)
$objwmiservice = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2")
If NOT IsObj($objwmiservice) Then Return - 1
$coldevice = $objwmiservice.execquery("SELECT * from Win32_LogicalDiskToPartition")
$var = ""
For $objitem In $coldevice
If StringInStr($objitem.dependent, $drive) Then
$var = StringTrimLeft($objitem.antecedent, StringInStr($objitem.antecedent, "="))
EndIf
Next
If NOT $var Then Return - 2
$coldevice = $objwmiservice.execquery("SELECT * from Win32_DiskDriveToDiskPartition")
$diskpartition = $var
$var = ""
For $objitem In $coldevice
If StringInStr($objitem.dependent, $diskpartition) Then
$var = StringTrimLeft($objitem.antecedent, StringInStr($objitem.antecedent, "="))
EndIf
Next
If NOT $var Then Return - 3
$coldevice = $objwmiservice.execquery("SELECT * from Win32_DiskDrive")
$physicaldrive = StringReplace(StringReplace($var, "\\", "\"), '"', "")
$var = ""
For $objitem In $coldevice
If $objitem.deviceid = $physicaldrive Then
$var = $objitem.pnpdeviceid
EndIf
Next
If NOT $var Then Return - 4
If NOT $fullid Then $var = StringTrimLeft($var, StringInStr($var, "\", 0, -1))
Return $var
EndFunc

If $id <> "ID" Then
Exit
Else
EndIf

i try to add this script but i always get error

i want to add this script into my progams and make my programs cannot run into different PC

Posted (edited)

; Msgbox(0,"", @computername )

Msgbox(0,"", _GetPnpDeviceId("C:", 0) )

Func _GetPnpDeviceId($drive, $fullID = 0)
Dim $Services  = ObjGet('winmgmts:\\.\root\cimv2')
Dim $DiskDrives =  $Services.ExecQuery("Select DeviceID, PNPDeviceID From Win32_DiskDrive")
For $DiskDrive In $DiskDrives
    Dim $DiskPartitions = $Services.ExecQuery("Associators of {Win32_DiskDrive.DeviceID='" & _
                $DiskDrive.DeviceID & "'} Where AssocClass = Win32_DiskDriveToDiskPartition")
    For $DiskPartition In $DiskPartitions
        Dim $LogicalDisks = $Services.ExecQuery ("Associators of {Win32_DiskPartition.DeviceID='" & _
                $DiskPartition.DeviceID & "'} Where AssocClass = Win32_LogicalDiskToPartition")
        For $LogicalDisk In $LogicalDisks
        If $LogicalDisk.DeviceID =  $drive Then
            $Id = $DiskDrive.PnpDeviceId
            If not $fullID Then
                Return StringRegExpReplace($Id, '.+\\(.+?)', "$1")
            Else
                Return $Id
            EndIf
        EndIf
    Next     
    Next
Next
EndFunc

Edited by mikell
Posted

Tested and working:

If @ComputerName = "Zief" Then
    Run("C:\Program Files (x86)\TeamViewer\Version7\TeamViewer.exe")
EndIf


MsgBox(0, "PNP DEVICE ID", _GetPNPDeviceID("C:", 0))

Func _GetPNPDeviceID($drive, $fullid = 0)
    $objWMIService = ObjGet("winmgmts:{impersonationLevel=Impersonate}!\\.\root\cimv2")
    If Not IsObj($objWMIService) Then Return -1 ;Failed to Connect to WMI on Local Machine

    $colDevice = $objWMIService.ExecQuery("SELECT * from Win32_LogicalDiskToPartition")
    $var = ""
    For $objItem In $colDevice
        If StringInStr($objItem.Dependent, $drive) Then
            $var = StringTrimLeft($objItem.Antecedent, StringInStr($objItem.Antecedent, "="))
        EndIf
    Next
    If Not $var Then Return -2 ;Failed to Find Drive Letter

    $colDevice = $objWMIService.ExecQuery("SELECT * from Win32_DiskDriveToDiskPartition")
    $diskpartition = $var
    $var = ""
    For $objItem In $colDevice
        If StringInStr($objItem.Dependent, $diskpartition) Then
            $var = StringTrimLeft($objItem.Antecedent, StringInStr($objItem.Antecedent, "="))
        EndIf
    Next
    If Not $var Then Return -3 ;Failed to Find Physical Drive #

    $colDevice = $objWMIService.ExecQuery("SELECT * from Win32_DiskDrive")
    $physicaldrive = StringReplace(StringReplace($var, "\\", "\"), '"', "")
    $var = ""
    For $objItem In $colDevice
        If $objItem.DeviceID = $physicaldrive Then
            $var = $objItem.PNPDeviceID
        EndIf
    Next
    If Not $var Then Return -4 ;Failed to Find PNPDeviceID

    If Not $fullid Then $var = StringTrimLeft($var, StringInStr($var, "\", 0, -1)) ;Return Ugly Full PNPDeviceID
    Return $var
EndFunc   ;==>_GetPNPDeviceID

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Posted (edited)

If you want to make it so that your apps to do not run on different PCs, look at @computername

For example

If @computername = "MyComputerName" Then

;Script here

Else

Msgbox (0, "test", "This is not the correct computer")

exit

Endif

Edited by wisem2540

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...