Schrift
[thread]4410[/thread]

Win32::OLE wie jetz?

Leser: 3


<< |< 1 2 >| >> 11 Einträge, 2 Seiten
oblivion
 2006-02-28 16:11
#37160 #37160
User since
2006-01-17
24 Artikel
BenutzerIn
[default_avatar]
Hallo Leute,

kann mir jemand zufälligerweise ne Referenz im Web sagen, in der ich nachlesen kann, wie ich über die WMI einen neuen Prozess starten kann, oder zumindest ein Beispiel ?

Ich werde aus der HTML Seite zu Win32::OLE nicht schlau.


Gruß Oblivion
pktm
 2006-02-28 17:09
#37161 #37161
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
hier

Edit: Was genau möchtest du machen? Möchtest du Word starten?\n\n

<!--EDIT|pktm|1141139670-->
http://www.intergastro-service.de (mein erstes CMS :) )
oblivion
 2006-02-28 18:47
#37162 #37162
User since
2006-01-17
24 Artikel
BenutzerIn
[default_avatar]
hi, danke für Deine Antwort.

Was ich aber suche ist einen Prozess anzustarten über Win32::OLE

also die WMI.
Ich möchte gerne ein Programm remote anstarten und die Ausgabe in einer Datei speichern, weil ich nicht weiß, wie ich die Ausgabeumlenkung in diesem Fall hinbekomme ;-(
esskar
 2006-03-01 06:59
#37163 #37163
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
liegt das Programm schon dort?
wenn nein, kannst du es z.B. auf den Share \\computername\admin$ (existiert immer, du musst aber natürlich admin auf dem Computer sein) kopieren und dann so starten:

Quote
Launch Notepad Through WMI
In this example we launch a new process through a WMI method in the Win32_Process class. I have chosen a relatively innocuous application, Notepad, for the purpose of demonstration, but any executable can be substituted here. This capability can be extremely powerful for support personnel dealing with relatively inexperienced users. For example, rather than guide an end user through the user interface, menus, and so on to run a diagnostic tool, the support person can simply pop the tool up on the user's system using a script that invokes it remotely via WMI. This alone can be a big timesaver:

set process = GetObject("winmgmts:{impersonationLevel=impersonate}!Win32_Process")
result = process.Create ("notepad.exe",null,null,processid)
WScript.Echo "Method returned result = " & result
WScript.Echo "Id of new process is " & processed
There are a couple of new concepts in this example. The first new development is the use of the COM moniker notation in the GetObject() call when asking for the Win32_Process class. A moniker is a COM standard mechanism for encapsulating the location and binding of another COM object. This lets you get back a particular object based on the display name. Next, rather than submitting a query through ExecQuery() to get back instances of the Win32_Process class, I have asked to get back the class object itself. The reason for this is fairly simple, but may not be obvious. Creating a new process is not really an action to be taken against an existing process instance. Which currently running process should be the one to launch the new one? Because there is no consistent answer to this issue, it becomes apparent that creating a process is really creating a new instance of the Win32_Process class. Therefore, the concept of a static method, one defined against the class definition itself instead of its instances, is needed. The Create() method for Win32_Process is an example of such a static method; previous method examples have all been dynamic methods&—those that operate against individual instances. Incidentally, the Delete() method is a dynamic method because it typically applies to particular instances rather than the class as a whole.

The Create() method takes several input parameters, but in the example I simply supply the name of the executable I wish to launch, "notepad.exe." Aside from returning a value for success or failure of the operation, the method also returns the ID of the new process that was created. The script displays the method execution results and process ID values after the method is executed and, of course, the Notepad application should appear on your desktop.
oblivion
 2006-03-01 12:32
#37164 #37164
User since
2006-01-17
24 Artikel
BenutzerIn
[default_avatar]
ja sowas in der Art habe ich schon hinbekommen,
ich weiß nur nicht, wie ich die Ausgabe davon in ner Datei speichern kann, oder am besten in die Registry schreiben kann, das ist ja VBS
esskar
 2006-03-01 15:00
#37165 #37165
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
schau dir das mal an

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
use Win32::OLE;

# Your usual option-processing sludge.
my %opts;
GetOptions (\%opts, 'help|h|?', 'remote=s')
or pod2usage (2);

(exists $opts{'help'})
and pod2usage ('-exitstatus' => 0, '-verbose' => 2);

# Ensure exactly one argument after options.
scalar @ARGV == 1
or pod2usage (2);

my ($class) = @ARGV;

# Bomb out completely if COM engine encounters any trouble.
Win32::OLE->Option ('Warn' => 3);

# Get a handle to the SWbemServices object of the machine.
my $computer = Win32::OLE->GetObject (exists $opts{'remote'}
? "WinMgmts://$opts{'remote'}/"
: 'WinMgmts:');

# Get the SWbemObjectSet of all objects of the class.
my $instances_set = $computer->InstancesOf ($class);

# Convert set to Perl array.
my @instances = Win32::OLE::Enum->All ($instances_set);

# Display all properties of an object.
sub dump_obj ($) {
my ($obj) = @_;
# Get set of properties of the class.
my $props_set = $obj->{'Properties_'};

# Convert set to Perl array.
my @props = Win32::OLE::Enum->All ($props_set);
foreach my $prop (@props) {
my $name = $prop->{'Name'};
printf "%32s ", $name;
my $value;
if ($prop->{'IsArray'}) {
$value = '<array>';
}
else {
$value = $prop->{'Value'};
defined $value
or $value = '<undefined>';
}
print "$value\n";
}
}

foreach my $instance (@instances) {
dump_obj ($instance);
print "\n";
}

exit 0;



=head1 NAME

instances.pl - Dump all instances of a WMI class

=head1 SYNOPSIS

instances.pl [ options ] <WMI class name>

Options:

--help Display help and exit
--remote <host> Operate on <host> instead of local machine

=head1 SEE ALSO

http://msdn.microsoft.com/library/en-us/wmisdk/wmi/wmi_classes.asp


call:

instances.pl Win32_Battery
oblivion
 2006-03-02 12:35
#37166 #37166
User since
2006-01-17
24 Artikel
BenutzerIn
[default_avatar]
hallo Esskar, vielen Dank für deinen Beitrag.

Das hat mir schon ein bißchen weitergeholfen. Du hast nicht zufällig eine Dokumentation zu Win32::OLE und Prozessen?

Ich blicke durch die Doku von perldoc nicht wirklich durch und komme echt nicht weiter mit meinem Problem


Gruß Oblivion
esskar
 2006-03-02 17:24
#37167 #37167
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Const SW_NORMAL = 1
strComputer = "ams-cl2"
strCommand = "WhatsUp.exe"
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}" _
    & "!\\" & strComputer & "\root\cimv2")

Set objStartup = objWMIService.Get("Win32ZZZProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = HIDDEN_WINDOW

' Create Notepad process
Set objProcess = objWMIService.Get("Win32_Process")
intReturn = objProcess.Create _
   (strCommand, Null, objConfig, intProcessID)
If intReturn <> 0 Then
   Wscript.Echo "Process could not be created." & _
       vbNewLine & "Command line: " & strCommand & _
       vbNewLine & "Return value: " & intReturn
Else
   Wscript.Echo "Process created." & _
       vbNewLine & "Command line: " & strCommand & _
       vbNewLine & "Process ID: " & intProcessID
End If


als vb
mit perl geht es genauso\n\n

<!--EDIT|esskar|1141332833-->
Gast Gast
 2006-03-02 22:06
#37168 #37168
Und das ist mein Problem, ich bin zu doof um das in Perl umzusetzen ;-(((

ich habs in VBS hinbekommen, aber bei Perl geh ich total am Stock. *heul*

Trotzdem vielen Dank für deine Hilfe
renee
 2006-03-03 14:04
#37169 #37169
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Es lohnt sich meist, mal bei den Perlmonks zu suchen, dort gibt es ziemlich viele Threads zu CPAN:Win32::OLE zu finden...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
<< |< 1 2 >| >> 11 Einträge, 2 Seiten



View all threads created 2006-02-28 16:11.