以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如果打开过office系列的word 或者excel 或者PPT任何一个之后,再次点击打开其他图片或这个文件类型都会提示当前文件正在使用 有没有办法精准关闭当前已经打开过的进程 而不是关闭所有类型进程 比如word进程  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=169855)

--  作者:cnsjroom
--  发布时间:2021/7/3 17:40:00
--  如果打开过office系列的word 或者excel 或者PPT任何一个之后,再次点击打开其他图片或这个文件类型都会提示当前文件正在使用 有没有办法精准关闭当前已经打开过的进程 而不是关闭所有类型进程 比如word进程
麻烦老师帮忙看看   为什么打开图片类型的后再次打开图片类型 不会出错
如果打开过office系列的word 或者excel 或者PPT任何一个之后,再次点击打开其他图片或这个文件类型都会提示当前文件正在使用  有没有办法精准关闭当前已经打开过的进程  而不是关闭所有类型进程  比如word进程
代码如下:
Dim wb As WinForm.WebBrowser = e.Form.Controls("WebBrowser1")
Dim pc As WinForm.PictureBox = e.Form.Controls("PictureBox1")
wb.Address=""
pc.Image=getimage("")

\'判断目录是否存在,如果存在就先删除,再创建,如果不存在就直接创建,确保后续程序可以保存文件并进行阅读或使用
If FileSys.DirectoryExists(ProjectPath & "\\Reports") Then \'
    FileSys.DeleteDirectory(ProjectPath & "\\Reports",2,2)
    FileSys.CreateDirectory(ProjectPath & "\\Reports")
Else
    FileSys.CreateDirectory(ProjectPath & "\\Reports")
End If

Dim pc2 As WinForm.PictureBox = Forms("主窗口").Controls("PictureBox1")
Dim kp As WinForm.TabControl = Forms("主窗口").Controls("TabControl1")
Dim web1 As WinForm.WebBrowser = e.Form.Controls("WebBrowser1")
If FileSys.DirectoryExists(ProjectPath & "\\Reports") Then \'
Else
    FileSys.CreateDirectory(ProjectPath & "\\Reports")
End If

If Tables("主窗口_table1").Current Is Nothing Then
    Return
Else
    Dim dr As DataRow = Tables("主窗口_table1").Current.DataRow
    Dim fl As String =  ProjectPath & "Reports\\" &  dr("文件名")
    wjdz=fl
    
    Dim str As String = dr("文件名")
    Dim Parts() As String = str.Split(".")
    vars("文件名")= Parts(0)
    \'MessageBox.Show(vars("文件名"))
    If FileSys.FileExists(fl) AndAlso CRCCheckFile(fl) = dr.SQLGetValue("CRC值") Then \'如果本地存在同名文件且CRC校验值相同
        \'则直接使用本地文件
        If fl.EndsWith(".jpg") OrElse fl.EndsWith(".png") OrElse fl.EndsWith(".bmp") OrElse fl.EndsWith(".gif") OrElse fl.EndsWith(".ico") Then
            pc2.Image= GetImage(fl)
            kp.SelectedIndex=1
        Else If fl.EndsWith(".mp4") OrElse fl.EndsWith(".wmv") OrElse fl.EndsWith(".mpg") OrElse fl.EndsWith(".avi") OrElse fl.EndsWith(".m2ts") OrElse fl.EndsWith(".mp3") Then
            kp.SelectedIndex=3
            e.Form.Controls("Panel2").Basecontrol.controls("mplayer").url = fl
        Else  If  fl.EndsWith(".zip") OrElse fl.EndsWith(".rar")  OrElse fl.EndsWith(".exe") OrElse fl.EndsWith(".ppt") OrElse fl.EndsWith(".pptx")Then  \'fl.EndsWith(".txt") OrElse fl.EndsWith(".pdf") OrElse
            Dim Proc As New Process \'打开文件
            Proc.File = fl
            Proc.Start()
        Else
            web1.OfficeToolBar = False
            web1.Address = fl
            kp.SelectedIndex=4
        End If
    Else \'否则从数据库提取文件
        If dr.SQLLoadFile("附件",fl) = False Then \'如果提取文件失败
            Messagebox.Show("附件提取失败,可能并不存在附件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        Else
            If fl.EndsWith(".jpg") OrElse fl.EndsWith(".png") OrElse fl.EndsWith(".bmp") OrElse fl.EndsWith(".gif") OrElse fl.EndsWith(".ico") Then
                pc2.Image= GetImage(fl)
                kp.SelectedIndex=1
            Else If fl.EndsWith(".mp4") OrElse fl.EndsWith(".wmv") OrElse fl.EndsWith(".mpg") OrElse fl.EndsWith(".avi") OrElse fl.EndsWith(".m2ts") OrElse fl.EndsWith(".mp3") Then
                kp.SelectedIndex=3
                e.Form.Controls("Panel2").Basecontrol.controls("mplayer").url = fl
            Else  If  fl.EndsWith(".zip") OrElse fl.EndsWith(".rar")  OrElse fl.EndsWith(".exe") OrElse fl.EndsWith(".ppt") OrElse fl.EndsWith(".pptx") Then  \'fl.EndsWith(".txt") OrElse fl.EndsWith(".pdf") OrElse
                Dim Proc As New Process \'打开文件
                Proc.File = fl
                Proc.Start()
            Else
                web1.OfficeToolBar = False
                web1.Address = fl
                kp.SelectedIndex=4
            End If
        End If
    End If
End If
Dim zt As WinForm.Button = Forms("主窗口").Controls("停止播放")
zt.PerformClick
[此贴子已经被作者于2021/7/5 10:43:53编辑过]

--  作者:有点蓝
--  发布时间:2021/7/3 17:56:00
--  
试试
……
    If FileSys.FileExists(fl) AndAlso CRCCheckFile(fl) = dr.SQLGetValue("CRC值") Then \'如果本地存在同名文件且CRC校验值相同
web1.Address = nothing
        \'则直接使用本地文件
        If fl.EndsWith(".jpg") OrElse fl.EndsWith(".png") OrElse fl.EndsWith(".bmp") OrElse fl.EndsWith(".gif") OrElse fl.EndsWith(".ico") Then
            pc2.Image= GetImage(fl)
            kp.SelectedIndex=1
        Else If fl.EndsWith(".mp4") OrElse fl.EndsWith(".wmv") OrElse fl.EndsWith(".mpg") OrElse fl.EndsWith(".avi") OrElse fl.EndsWith(".m2ts") OrElse fl.EndsWith(".mp3") Then


--  作者:cnsjroom
--  发布时间:2021/7/3 18:06:00
--  回复:(有点蓝)试试……    If FileSys.F...
老师  试了  提示还是一样的  甚至直接在打开之前设置这个 都是一样的效果
--  作者:cnsjroom
--  发布时间:2021/7/5 9:09:00
--  回复:(有点蓝)试试……    If FileSys.F...
麻烦老师帮忙看看啊 
--  作者:有点蓝
--  发布时间:2021/7/5 9:33:00
--  
没有办法,只能杀掉进程了

Dim ps As  System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("WINWORD")
For Each p As System.Diagnostics.Process In ps
    If p.MainWindowTitle = Nothing Then  p.kill
Next

--  作者:cnsjroom
--  发布时间:2021/7/5 10:36:00
--  回复:(有点蓝)没有办法,只能杀掉进程了Dim ps As&...
杀掉进程的话  会导致程序之外的word文件要被一起干掉   在某种情况下不是很友好哦!


[此贴子已经被作者于2021/7/5 10:48:34编辑过]

--  作者:有点蓝
--  发布时间:2021/7/5 10:44:00
--  
5楼只杀掉浏览器里的进程,如果也杀掉其它word进程,这个就没有办法了
--  作者:cnsjroom
--  发布时间:2021/7/5 10:48:00
--  回复:(有点蓝)5楼只杀掉浏览器里的进程,如果也杀掉...
Dim ps As  System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("WINWORD")
For Each p As System.Diagnostics.Process In ps
    If p.MainWindowTitle = Nothing Then  p.kill
Next

这个代码也没有杀死浏览器里面的进程

--  作者:有点蓝
--  发布时间:2021/7/5 10:51:00
--  
关闭所有word文档。浏览器打开word后看看任务管理器里word进程名称是不是“WINWORD
--  作者:cnsjroom
--  发布时间:2021/7/5 12:07:00
--  回复:(有点蓝)关闭所有word文档。浏览器打开word后...
老师可以指导下怎么跟踪进程不呢    我在浏览器中打开文件  找不到进程

运行word文件后点击excel  PPT均可关闭word进程,
1、运行excel文件后点击word PPT就提示找不到excel具体的表名项目了  无法关闭进程 有没有办法解决呢? 
2、点击PPT会提示下载或保存  有没有办法直接下载并显示呢?】


当前代码如下:
Dim wb As WinForm.WebBrowser = e.Form.Controls("WebBrowser1")
Dim pc As WinForm.PictureBox = e.Form.Controls("PictureBox1")
wb.Address=""
pc.Image=getimage("")

Dim ps As  System.Diagnostics.Process() = System.Diagnostics.Process.GetProcesses()
For Each p As System.Diagnostics.Process In ps
    output.show(p.processName)
    If ("Excel" = p.ProcessName AndAlso p.MainWindowTitle = "")
        output.show(p.MainWindowTitle)
        p.kill
    End If
    If ("WINWORD" = p.ProcessName AndAlso p.MainWindowTitle = "")
        output.show(p.MainWindowTitle)
        p.kill
    End If
    If ("POWERPNT" = p.ProcessName AndAlso p.MainWindowTitle = "")
        output.show(p.MainWindowTitle)
        p.kill
    End If
Next


\'判断目录是否存在,如果存在就先删除,再创建,如果不存在就直接创建,确保后续程序可以保存文件并进行阅读或使用
If FileSys.DirectoryExists(ProjectPath & "\\Reports") Then \'
    FileSys.DeleteDirectory(ProjectPath & "\\Reports",2,2)
    FileSys.CreateDirectory(ProjectPath & "\\Reports")
Else
    FileSys.CreateDirectory(ProjectPath & "\\Reports")
End If

Dim pc2 As WinForm.PictureBox = Forms("主窗口").Controls("PictureBox1")
Dim kp As WinForm.TabControl = Forms("主窗口").Controls("TabControl1")
Dim web1 As WinForm.WebBrowser = e.Form.Controls("WebBrowser1")
If FileSys.DirectoryExists(ProjectPath & "\\Reports") Then \'
Else
    FileSys.CreateDirectory(ProjectPath & "\\Reports")
End If

If Tables("主窗口_table1").Current Is Nothing Then
    Return
Else
    Dim dr As DataRow = Tables("主窗口_table1").Current.DataRow
    Dim fl As String =  ProjectPath & "Reports\\" &  dr("文件名")
    wjdz=fl
    
    Dim str As String = dr("文件名")
    Dim Parts() As String = str.Split(".")
    vars("文件名")= Parts(0)
    \'MessageBox.Show(vars("文件名"))
    If FileSys.FileExists(fl) AndAlso CRCCheckFile(fl) = dr.SQLGetValue("CRC值") Then \'如果本地存在同名文件且CRC校验值相同
        web1.Address = Nothing
        \'则直接使用本地文件
        If fl.EndsWith(".jpg") OrElse fl.EndsWith(".png") OrElse fl.EndsWith(".bmp") OrElse fl.EndsWith(".gif") OrElse fl.EndsWith(".ico") Then
            pc2.Image= GetImage(fl)
            kp.SelectedIndex=1
        Else If fl.EndsWith(".mp4") OrElse fl.EndsWith(".wmv") OrElse fl.EndsWith(".mpg") OrElse fl.EndsWith(".avi") OrElse fl.EndsWith(".m2ts") OrElse fl.EndsWith(".mp3") Then
            kp.SelectedIndex=3
            e.Form.Controls("Panel2").Basecontrol.controls("mplayer").url = fl
        Else  If  fl.EndsWith(".zip") OrElse fl.EndsWith(".rar")  OrElse fl.EndsWith(".exe") Then \'OrElse fl.EndsWith(".ppt") OrElse fl.EndsWith(".pptx")Then  \'fl.EndsWith(".txt") OrElse fl.EndsWith(".pdf") OrElse
            Dim Proc As New Process \'打开文件
            Proc.File = fl
            Proc.Start()
        Else
            web1.OfficeToolBar = False
            web1.Address = fl
            kp.SelectedIndex=4
        End If
    Else \'否则从数据库提取文件
        If dr.SQLLoadFile("附件",fl) = False Then \'如果提取文件失败
            Messagebox.Show("附件提取失败,可能并不存在附件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        Else
            web1.Address = Nothing
            If fl.EndsWith(".jpg") OrElse fl.EndsWith(".png") OrElse fl.EndsWith(".bmp") OrElse fl.EndsWith(".gif") OrElse fl.EndsWith(".ico") Then
                pc2.Image= GetImage(fl)
                kp.SelectedIndex=1
            Else If fl.EndsWith(".mp4") OrElse fl.EndsWith(".wmv") OrElse fl.EndsWith(".mpg") OrElse fl.EndsWith(".avi") OrElse fl.EndsWith(".m2ts") OrElse fl.EndsWith(".mp3") Then
                kp.SelectedIndex=3
                e.Form.Controls("Panel2").Basecontrol.controls("mplayer").url = fl
            Else  If  fl.EndsWith(".zip") OrElse fl.EndsWith(".rar")  OrElse fl.EndsWith(".exe") Then \'OrElse fl.EndsWith(".ppt") OrElse fl.EndsWith(".pptx") Then  \'fl.EndsWith(".txt") OrElse fl.EndsWith(".pdf") OrElse
                Dim Proc As New Process \'打开文件
                Proc.File = fl
                Proc.Start()
            Else
                web1.OfficeToolBar = False
                web1.Address = fl
                kp.SelectedIndex=4
            End If
        End If
    End If
End If