qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Preliminary qemu-ifup support for windows
@ 2008-06-18  1:05 consul
  0 siblings, 0 replies; only message in thread
From: consul @ 2008-06-18  1:05 UTC (permalink / raw)
  To: qemu-devel

Is anybody interested in supporting qemu-ifup/down scripts on Windows hosts?
Here is a quick and dirty hack allowing to run vbscripts on qemu startup and 
shutdown. For start I have scripts that enable/disable the TAP0 device when 
qemu starts and exits, removing the notification icon from the taskbar when 
qemu is not running. I know, this can be done other ways, but it still nice 
to have the icons available, when needed, and scripts can do more than that. 
I still have not yet figured out how to turn the notification icon off when 
the qemu is connected and running, except manually refreshing the network 
connections window, any idea?

Here is my hack:


$ svn diff
Index: vl.c
===================================================================
--- vl.c        (revision 4744)
+++ vl.c        (working copy)
@@ -8680,6 +8680,8 @@
             }
         }
     }
+#else
+    run_script("cscript qemu-ifdown.vbs");
 #endif
     return 0;
 }
Index: tap-win32.c
===================================================================
--- tap-win32.c (revision 4744)
+++ tap-win32.c (working copy)
@@ -659,11 +659,23 @@
         tap_win32_free_buffer(s->handle, buf);
     }
 }
+void run_script(char *script){
+    STARTUPINFO sinfo;
+    PROCESS_INFORMATION pinfo;
+    memset(&sinfo,0,sizeof(sinfo));
+    sinfo.cb = sizeof(sinfo);
+    sinfo.wShowWindow = SW_HIDE;
+    sinfo.dwFlags = STARTF_USESHOWWINDOW;
+    CreateProcess(0,script,0,0,0,0,0,0,&sinfo,&pinfo);
+    WaitForSingleObject(pinfo.hProcess,INFINITE);
+    CloseHandle(pinfo.hThread);
+    CloseHandle(pinfo.hProcess);
+}

 int tap_win32_init(VLANState *vlan, const char *ifname)
 {
     TAPState *s;
-
+    run_script("cscript qemu-ifup.vbs");
     s = qemu_mallocz(sizeof(TAPState));
     if (!s)
         return -1;
Index: sysemu.h
===================================================================
--- sysemu.h    (revision 4744)
+++ sysemu.h    (working copy)
@@ -69,6 +69,7 @@

 /* TAP win32 */
 int tap_win32_init(VLANState *vlan, const char *ifname);
+void run_script(char *script);

 /* SLIRP */
 void do_info_slirp(void);

--------------
And here is a sample qemu_ifup.vbs script (substitute "Disa&ble" for 
"En&able" for ifdown)

set sh = createobject("wscript.shell")

Dim obj 'As Shell
Dim f 'As Folder
Dim itm 'As ShellFolderItem
Dim ix 'As ShellFolderItem
Dim net 'As Folder
Dim v 'As FolderItemVerb

Set obj = CreateObject("shell.application")
Set f = obj.Namespace(3)

For Each itm In f.Items
If itm.Name = "Network Connections" Then
    Set net = itm.GetFolder
    For Each ix In net.Items
        If ix.Name = "TAP0" Then
            For Each v In ix.Verbs
                If v.Name = "En&able" Then
                    v.DoIt
                End If
            Next
            Exit For
        End If
    Next
    Exit For
End If
Next
WScript.Sleep 1000

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-06-18  1:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-18  1:05 [Qemu-devel] Preliminary qemu-ifup support for windows consul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).