Sign in to follow this  
Followers 0
t0ddie

remove variable from an array

12 posts in this topic

#1 ·  Posted (edited)

well, im trying to list all processes.. and that works great on the beta

Dim $procs = ProcessList()

For $i = 1 To $procs[0]

MsgBox(4096, "", $procs[$i])

Next

i was wondering, if i wanted to take a process out of the loop.... how would i do that?

so lets say while listing, it comes to [8] and thats explorer.exe

how would i 'detect' that in the string, and skip it.. so it doesnt come up in the message box... but basically skips it.. from [7] to [9]

i tried a few things.. im stuck.

thanks.

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites



I am not running the current beta that has ProcessList in it so I cannot test this but you could do a couple things here.

1. If you know the process number in the list you can simply:

Dim $procs = ProcessList()
For $i = 1 To $procs[0]
If $i <> 8 then 
MsgBox(4096, "", $procs[$i])
endif
Next

2. If you know the name of the process you want to skip:

Dim $procs = ProcessList()
For $i = 1 To $procs[0]
if $procs[$i] <> "explorer.exe" Then
MsgBox(4096, "", $procs[$i])
EndIf
Next

You werent very clear on what exactly you wanted to happen, so I hope one of these can help.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

actually, while i was in bed last night, i thought of something.

Dim $procs = ProcessList()

For $i = 1 To $procs[0]

if $procs[$i] = "process name" then $i = $i + 1

MsgBox(4096, "", $procs[$i])

Next

i thought of that all on my own. im going to try it now. impressed? :ph34r:

EDIT: oh yeah, to explain what i wanted to do, i wanted to loop through the processes and exclude whatever processes i dont want to show in the msgbox

so, i could use this line, if $procs[$i] = "process name" then $i = $i + 1

would it be ok to nest something like this? for multiple names? such as.

Dim $procs = ProcessList()

For $i = 1 To $procs[0]

if $procs[$i] = "process name1" then $i = $i + 1

if $procs[$i] = "process name2" then $i = $i + 1

if $procs[$i] = "process name3" then $i = $i + 1

MsgBox(4096, "", $procs[$i])

Next

thanks

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

That works the same as:

Dim $procs = ProcessList()
For $i = 1 To $procs[0]
if $procs[$i] <> "explorer.exe" Then
MsgBox(4096, "", $procs[$i])
EndIf
Next

only it is poorly structured. no neec to do the increment, just have it skip the code that does the work in the loop. If you don't want to do it my way then how about this:

Dim $procs = ProcessList()
For $i = 1 To $procs[0]
if $procs[$i] = "process name" then ContinueLoop
MsgBox(4096, "", $procs[$i])
Next

It works just like yours but takes advantage of this rarely seen function.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

sweet, looks good. since im not super versed and familiar with the commands... i just dont know the best way to impliment ideas.

i was unaware that your code did the same thing, but was "cleaner" for lack of a better term.

thanks for the tips.

Dim $procs = ProcessList()

For $i = 1 To $procs[0]

if $procs[$i] <> "explorer.exe" Then

MsgBox(4096, "", $procs[$i])

EndIf

Next

i didnt get it at first, cause i was using the = sign. but i understand now. if less than or greater than explorer.exe.. meaning anything BUT explorer.exe

yeah, continueloop? heh.. reminds me of goto and gosub.

thanks matt!

ps.. can i do it like this?

Dim $procs = ProcessList()

For $i = 1 To $procs[0]

if $procs[$i] <> "1.exe" Then

if $procs[$i] <> "2.exe" Then

if $procs[$i] <> "3.exe" Then

MsgBox(4096, "", $procs[$i])

EndIf

Next

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Script suggestion,

Instead of listing all of the different applications that you want to stop hard coded into your script, you could place them in a text file then just loop through the contents of the text file. This will make your code more compact and maintainable. Just a thought, good luck!

*** Matt @ MPCS

EDIT: No every If statement must have a matching EndIf in this context. That is why I suggest the above. That way you don't need all of the If statements.

Edited by Matt @ MPCS

Share this post


Link to post
Share on other sites

actually, this keeps what i want, and ends everything else

whatever processes i want to keep, ill just hardwire those.. and skip those.. like the system processes. and only processes that are ok to end will i include in the message box

of course, the endprocess command isnt in this code yet. but it will be. just need to change the message box to "ok" "cancel" and add the process close command if clicked ok

Dim $procs = ProcessList()

For $i = 1 To $procs[0]

if $procs[$i] <> "itsAkeeper1.exe" Then

if $procs[$i] <> "itsAkeeper2.exe" Then

if $procs[$i] <> "itsAkeeper3.exe" Then

MsgBox(4096, "", $procs[$i])

EndIf

Next


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

Either way this list is not going to be static so it will be a pain to maintain. Wouldn't it be better if you could compile an engine that ran dynamically based on the contents of a reference file? Just because the processes required for this computer change means that you need to go through and change the script? that sucks!

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

well yeah, it would be cool if it updated itself.

but it will include all the basic system processess.. to date so far...

and a message box will let you choose to end the rest if you wish.

so maybe yeah.. a new process will come out when microsoft releases another update.

it wont get skipped, like the other processes that your computer needs, and the user will have the choice to end it. but most processes the system uses will be skipped, so the user doesnt have a choice to end those.

so, either way...

you have a good idea though. makes sense.

i just want to know, if this is "correct" methods for coding.. because im not sure if this will function smoothly if i nest those commands for each process to skip.

so, im sure it will work, but i want to know if its.. "proper" to use the command like that.

i think larry mentioned something in a previous post about my nesting of if's

i dont know if this is the same scenerio.. but if i was to use a new line for each "if" command in this fashion.. would it be suitable?

EDIT: would "and" be more appropriate? with a "then" at the end?

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

I wouldn't do it that way. If you really think you need to hard code the system processes then I suggest going back to this:

Dim $procs = ProcessList()
For $i = 1 To $procs[0]
if $procs[$i] = "process name1" then ContinueLoop
if $procs[$i] = "process name2" then ContinueLoop
if $procs[$i] = "process nameN" then ContinueLoop
MsgBox(4096, "", $procs[$i])
Next

That way you don't have to worry about the congestion of nested Ifs. That will make your life easier.

For the record, it will be far less typing for you if you were to use an external file also but it is your script do whatever you feel is necisary to get it running.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

thanks. just replying to say thanks.

lol, i think i have wasted enough space... but at least i learned something

ATTENTION EVERYONE

im taking the day to go run in the woods, and get all naturey

i suggest if you have been in front of the keyboard alot lately, that you do the same.

its hard... i know!

peace

~Toddie


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

thanks. just replying to say thanks.

lol, i think i have wasted enough space... but at least i learned something

ATTENTION EVERYONE

im taking the day to go run in the woods, and get all naturey

i suggest if you have been in front of the keyboard alot lately, that you do the same.

its hard... i know!

peace

~Toddie

<{POST_SNAPBACK}>

wow, that gives me some jonesing for the ol' Fantasy LARPing...

"I'm not even supposed to be here today!" -Dante (Hicks)

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
Sign in to follow this  
Followers 0