please solve my problem

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
dileep
Posts: 29
Last visit: Mon Oct 26, 2009 3:17 pm

please solve my problem

Post by dileep »

hi jvierra thanks for u r programs............but in u r program if i click the radiobutton then it will go to subroutine myevent. there i want to stop or start the process using objservice.startservice so how can i pass the objservice parameter to the 'myevent' please reply me
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

please solve my problem

Post by jvierra »

Here is a new one with a sample of how to get the service name back to the event.

uploads/2491/WMITable.hta.txt

User avatar
dileep
Posts: 29
Last visit: Mon Oct 26, 2009 3:17 pm

please solve my problem

Post by dileep »

hi jvierra

Thanks for u r quick replies....................and please help form the below problem In the below program how can i check the checkbox by default.
how can i verify whether a checkbox is checked or not

and how can i add checkboxes to the dependet services too......


please help me..........

please help me..........that is u r program i modified a little bit (not in code just some logic i modified)


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META http-equiv=Content-Type content="text/html; CHARSET=iso-8859-1">
<script type="text/vbscript">

Dim wmi ' global visibility
dim qw(200)
i=0
strComputer = "172.16.0.125"
Set wmi = GetObject("winmgmts:" & strComputer & "rootcimv2")


Set colListOfServices = wmi.ExecQuery("Select * from Win32_Service")



Sub window_onLoad()





For Each objService in colListOfServices
i=i+1
set r = tbl1.insertRow(-1)
MakeCell r, objService.DisplayName
If objService.State = "Running" Then
Set c = MakeCell( r, "Start")
Set cb = document.createElement("input")
cb.type = "checkbox"
cb.value = objService.DisplayName
c.innerHTML = "stop"

Set cb1 = document.createElement("input")

cb1.type = "checkbox"
cb1.value = objService.DisplayName
cb.attachEvent "onclick", getRef("myevent")
c.appendChild cb
cb1.attachEvent "onclick", getRef("myevent1")
c.appendChild cb1
c.appendChild cb2

ElseIf objService.State = "Stopped" Then
Set c = MakeCell( r, "Start")
Set cb = document.createElement("input")
cb.type = "checkbox"
cb.value = objService.DisplayName
c.innerHTML = "stop"

Set cb1 = document.createElement("input")
cb1.type = "checkbox"
cb1.value = objService.DisplayName
cb.attachEvent "onclick", getRef("myevent")
c.appendChild cb
cb1.attachEvent "onclick", getRef("myevent1")
c.appendChild cb1


End If
MakeCell r, objService.StartMode
Set c = MakeCell( r, "" )
Set t = MakeTable(objService.Name)
c.appendChild t

Next

End Sub

Sub myevent()

j=1

For Each ob1 in colListOfServices

if ob1.DisplayName=window.event.srcElement.value then
msgbox "in if"
ob1.StopService()
end if
j=j+1
next
End Sub

Sub myevent1()
j=1

For Each ob1 in colListOfServices

if ob1.DisplayName=window.event.srcElement.value then
msgbox "in if"

ob1.StartService()
end if
j=j+1
next
End Sub

Function MakeCell( row, text)

set c = row.insertCell(-1)
c.className = "p1"
c.innerHTML = text
Set MakeCell = c

End Function

Function MakeTable(sName)
Set services = wmi.ExecQuery("Associators of

{Win32_Service.Name='" & sName & "'} Where AssocClass=Win32_DependentService

Role=Antecedent" )

Set t = document.createElement("table")
t.className = "t_chld"
t.title = "my tble"

If services.Count > 0 then
For Each s in services
Set r = t.insertRow(-1)
Set c = r.insertCell(-1)
Set cb1 = document.createElement("input")
cb1.type = "checkbox"
c.className = "p2"
c.InnerHTML = s.Name
Next
End If

Set MakeTable = t

End Function

</script>
</head>
<style type="text/css">
.p1{
overflow: hidden;
border-collapse: collapse;
vertical-align: top;
empty-cells: show;
font-family: Arial;
font-size:8pt;
font:menu;
padding:0pt;
margin: 0;
border: 1px;
border-style: solid;
border-color: black;
width: 60%;
}
.p2 {
color: red;
padding:0pt;
font-family: Arial;
font-size:8pt;
font:menu;
margin: 0;
border: 0;
border-style: solid;
border-color: white;
}
</style>
<body>
<div>
<table id="tbl1" width="80%">
<caption><h2>Services Status<h2></h2></caption>
<thead>
<tr>
<td>Name</td>
<td>State</td>
<td>StartMode</td>
<td>Dependencies</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</body>
</html>



please solve my problem
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

please solve my problem

Post by jvierra »

Please try to post long listings as an attachment in a file as it is much easier to obtain and read that way.

Set c = MakeCell( r, "Stop") Set cb = document.createElement("input") cb.type = "checkbox" cb.value = objService.DisplayName cb.attachEvent "onclick", getRef("myevent") c.appendChild cb cb.checked = true
You have to set "checked" to true AFTER adding the CB to the CELL or it will get cleared when it is added.


User avatar
dileep
Posts: 29
Last visit: Mon Oct 26, 2009 3:17 pm

please solve my problem

Post by dileep »

uploads/31244/services.txthi jvierra, thanks for u r suggestions. thanks aloti am attaching my program in this post in that program in dependent services part some error is comingand the checkbox is not checking if i give default checking.so please going through the code and solve the problem
dileep2009-08-21 03:45:36
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

please solve my problem

Post by jvierra »

Consider getting an editor.

Sapien has a free editor that you can download. It will help you keep the code from getting broken.

http://www.primaltools.com/downloads/communitytools/

Look for PrimalPad.

The code changes you have made don't make much sense. Please go back to my original code and make only one change at a time. Ask a question as soon as yuo have an issue. The changes that you have made seem to be just randomly pasted into the document. If you have a reason it is not cler what that reason is. You ask about teh checkbox but I see all kinds of other things.

You should not put processing code outside of a function or subroutine except for variable declarations that you want to have global visibility.

From the vars (i,j) that you have sprinkled in I can see that you don't understand teh DHTML model. These vars will not be changed after an event ends so they are not counting anything.

Back up and try to o only one thing at a time. First understand what teh code is doing.

I also see that you are trying to add buttons to the dependency list. Why?

Are you trying to recreate the "services.msc" applet? Even that doesn't approach this the way you are. It uses a "restart" idea with a report on what dependencies will be restarted also.

I will look at it some more later but this is all I can do right now.


jvierra2009-08-21 08:01:45
User avatar
Alexander Riedel
Posts: 8488
Last visit: Tue Apr 16, 2024 8:42 am
Answers: 20
Been upvoted: 37 times

please solve my problem

Post by Alexander Riedel »

Topic moved by moderator.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
dileep
Posts: 29
Last visit: Mon Oct 26, 2009 3:17 pm

please solve my problem

Post by dileep »

hi jvierra, ......thaks for u r reply yes i want to create services.msc applet kind thingso i want to create check boxes to the dependencies also if i click the check box the service has to be start if i deselect it has to be stopin the program i copied some code globally because in myevent i have to start or stop service so i have to access the objservice in this myevent subroutine also thats why i made it globally or is there any other way stop or start service in my event and in dependent services part i gave cb4.checked= true then also it is not selecting i think some logical error is there please solve iti dont know dhtml...........please please solve it
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

please solve my problem

Post by jvierra »

Please run my excamples. Look very carefull at how it is structure.

You will ned to figure this out on your own. I have given you all of the information you need in order to do this. Now you need to put in the time learning how to make it work.

I see no reason to rebuild the functionality of of Services.msc since it comes on every system and does everything you are trying to do. If you are just rtying to learn how to write an HTA then keep working at it. If yu ask a specific question we will rty and answer it.

We will not write your code for you but wil post what we may have.

This forum is really aligned to teaching scripting and solving technical issues. We also answer qustions for anyone trying to learn scripting.

YOu say you don't know DHTML. I have posted links to many resources that will help you learn DHTML and scripting.

Good luck and post back with a specific question.

This topic is 14 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked