squirrelc0de

excluding certain computers with @computername macro

8 posts in this topic

#1 ·  Posted

Hi there, 

Im working on trying to exclude one computer from getting a file to run when a user logs onto it. I cant seem to figure out how to properly create a function to do this. What am I missing to get the .exe to not run if a user signs into a specific computer? 

 

Func testfunction()
   if (@ComputerName <> "computer1") Then
      Run(@ComSpec & " /c " & "\\server\directory\program.exe","", @SW_HIDE)
   ElseIf (@ComputerName = "computer1") then Exit
   EndIf

EndFunc

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

How many computers do you have? Maybe make an array with all the computer names you want to run the program on, and not include the ones you don't want.

 

#Include <Array.au3>

Global $Comp_List['computer2', 'computer3', 'computer4', ...etc]

Func testfunction()
   For $i = 1 to Ubound($Comp_List) - 1
      Run(@ComSpec & " /c " & "\\server\directory\program.exe","", @SW_HIDE) ; Not sure where you input the computer name in this command line.
      ; For the computer name do this wherever it is you put it. $Comp_List[$i]
   Next

EndFunc

 

Edited by FengHuangWuShen

Share this post


Link to post
Share on other sites

#3 ·  Posted

Hi there, I only have one computer Computer1 in this case that i need to exclude. I would just need the login script to check if a user is logging ionto computer1 to block the installation of that one specific file. 

I could however use an array to exclude that machine but how would i get the login script to close the program if a user is logging onto that specific computer im trying to block file access to?

Share this post


Link to post
Share on other sites

#4 ·  Posted

If the script is running at login, then I think you could get away with doing something like this:
 

While 1
    ProcessWait('Notepad.exe', 0)
    MsgBox(0, 'Process Watcher', 'Process is active')
    Run('taskkill /IM notepad.exe /F')
    Exit
WEnd

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Thank you for your help, however i still need help trying to get this to work. 
the while loop is a good idea and taskkill will solve killing the application in question on the one machine. However I still need the application to run on every other machine but computer1. That;s why I had thought of using the crude if,elseif statement up at the top. 

i am using the AD scriptlets, but I cannot seem to get this to work properly: 
 

#include <AD.au3>

func testfunction()
_AD_Open()

If _AD_IsMemberOf("included computers") then
   Run(@ComSpec & " /c " & "\\server\directory\program.exe","", @SW_HIDE)

   ElseIf _AD_IsMemberOf("excluded computers") then 
       Run('taskkill /IM program.exe /F')
   EndIf

    _AD_Close()
EndFunc

What am i missing to kill the software from starting on the excluded computer ( just one computer)

Share this post


Link to post
Share on other sites

#6 ·  Posted

That's why I suggested using an array with the names that you want to execute the termination script on. If the computer1 is not in the array, then it will be ignored.
 

Share this post


Link to post
Share on other sites

#7 ·  Posted

Why not just have:

If @ComputerName = "Computer1" Then Exit

;~ Rest of your code goes down below

 

Share this post


Link to post
Share on other sites

#8 ·  Posted

thats exactly what i was looking for! Thank you @Subz

Share this post


Link to post
Share on other sites

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