salt控制windows 窗口不显示

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了salt控制windows 窗口不显示相关的知识,希望对你有一定的参考价值。

参考技术A  在windows下通过Salt-Minion-xxxx.xx.x-AMD64-Setup.exe安装salt-minion的时候,默认是安装并开机启动salt-minion服务。但是如果以服务的方式启动salt-minion的话,windows的可视化操作是不能被控制的。为了能够通过salt-minion来操控windows的可视化界面,需要禁用salt-minion服务,并且用进程的方式启动salt-minion。

解决方案如下:
1. 开始>>运行>>services.msc 将salt-minion服务给停止并将启动类型设为手动

2.命令行方式运行C:\salt\salt-minion.bat
  
3.测试效果:salt '*w7' cmd.run 'start notepad'

windows下使用salt安装软件

https://docs.saltstack.com/en/latest/topics/windows/windows-package-manager.html

可以看官网文档,本人英文差,翻译不好,谅解

在2015.8.0及更高版本中,Windows Software Repository缓存是在Salt Minion上编译的

SaltStack Windows软件资源库提供了一个软件包管理器和软件资源库,类似于Linux上的yum和apt提供的资源库。该存储库可以使用远程Windows系统上的安装程序来安装软件。

In many senses, the operation is similar to that of the other package managers salt is aware of:

the pkg.installed and similar states work on Windows.

the pkg.install and similar module functions work on Windows.

和yum的区别

1,存储库元数据(SLS文件)通过salt或git托管。

2,软件包可以从salt仓库,git仓库或http(s)或ftp URL下载。

3,包之间的依赖关系需要手动管理。

使用之前的要求是:GitPython 0.3或更高版本,或者在Salt mast上安装libgit 0.20.0或更高版本的pygit2 0.20.3。Windows软件包定义是使用Git下载和更新的。

默认情况下salt不会进行分发用于安装Windows软件包的SLS文件,需要运行以下命令以初始化您的Salt主机上的存储库:

salt-run winrepo.update_git_repos
SYNC REPO TO WINDOWS MINIONS

Run pkg.refresh_db on each of your Windows minions to synchronize the package repository.

salt -G'os : windows'pkg.refresh_db

接下来就可以安装windows软件

显示已安装的软件包 salt -G'os : windows'pkg.list_pkgs

您可以使用Salt pkg模块查询软件包的可用版本 salt winminion pkg.list_available firefox

安装最新版本的Firefox salt winminion pkg.install'firefox '

卸载WINDOWS软件
使用pkg模块卸载软件

salt winminion pkg.remove firefox
salt winminion pkg.purge firefox
Note

pkg.purge just executes pkg.remove on Windows. At some point in the future pkg.purge may direct the installer to remove all configs and settings for software packages that support that option

存储库位置
Salt维护SLS文件的存储库来安装大量的Windows软件包:

2015.8.0及以后的版本:https://github.com/saltstack/salt-winrepo-ng
早期版本:https://github.com/saltstack/salt-winrepo
默认情况下,这些存储库被镜像到/srv/salt/win/repo-ng 和/srv/salt/win/repo。

通过设置winrepo_dir_ng和winrepo_dir选项,可以在主配置文件中更改此位置 。

MAINTAINING WINDOWS REPO DEFINITIONS IN GIT REPOSITORIES
可以托管在一个或多个Git存储库中,默认存储库由SaltStack托管在GitHub上。这些包括各种开源软件项目的软件定义文件。这些软件定义文件是.sls文件。有两个默认的存储库:salt-winrepo和salt-winrepo-ng。salt-winrepo 包含旧版本(旧版本2015.8.0)的软件定义文件。salt-winrepo-ng是为更新的奴才(2015.8.0和更新)。

每个软件定义文件都包含salt在安装该软件所需的所有信息,包括安装程序文件的HTTP或FTP位置,用于静默安装的所需命令等, Anyone is welcome to send a pull request to this repo to add new package definitions. The repos can be browsed here: salt-winrepo salt-winrepo-ng

Note

The newer software definition files are run through the salt's parser which allows for the use of jinja.

通过修改或扩展winrepo_remotes和 winrepo_remotes_ng选项,配置主服务器可以搜索包定义的那些git存储库。

Important

winrepo_remotes was called win_gitrepos in Salt versions earlier than 2015.8.0

软件包定义通过运行winrepo.update_git_reposrunner 从online存储库中取出 。该命令在主服务器上运行:

控制台程序不显示dos窗口的方法

在实际项目中,为了实现某些功能,但是不希望给用户显示windows窗口或者dos窗口时,以下是比较常用的两种方式实现窗口隐藏:

方法1

在头文件下加上一句预处理命令:

#pragma comment( linker, "/subsystem:\\"windows\\" /entry:\\"mainCRTStartup\\"" ) // 设置入口地址

这样编译出来的exe就无dos窗口了

完整程序如下:

#include<windows.h>
#pragma comment( linker, "/subsystem:\\"windows\\" /entry:\\"mainCRTStartup\\"" ) // 设置入口地址
int main()

    MessageBox(NULL,"Hello","Notice",NULL);
    return 0;

方法2

使用vb实现程序隐藏:

set objShell=wscript.createObject("wscript.shell")  
iReturn=objShell.Run("你的程序.exe", 0, FALSE)  

'Run()
'第一个参数是你要执行的程序的路径,亦可传参
'第二个参数是窗口的形式,0后台运行;1正常运行;2最小化;3最大化;缺省的话表示正常运行
'第三个参数是表示这个脚本是等待还是继续执行,如果设为了True,脚本就会等待调用的程序退出后再向后执行。

方法3

使用ShellExecuteEx API函数,示例代码如下:

    SHELLEXECUTEINFO ShellInfo;
    memset(&ShellInfo, 0, sizeof(ShellInfo));

    ShellInfo.cbSize = sizeof(ShellInfo);
    ShellInfo.hwnd = NULL;
    ShellInfo.lpVerb = _T("open");
    ShellInfo.lpFile = szFilePath; // 此处写执行文件的绝对路径
    ShellInfo.nShow = SW_SHOWNORMAL;
    ShellInfo.fMask = SEE_MASK_NOCLOSEPROCESS;//无控制台
    BOOL bResult = ShellExecuteEx(&ShellInfo);

或者

DWORD ShellRun(CString csExe, CString csParam,DWORD nShow)  
  
	SHELLEXECUTEINFO ShExecInfo;  
	ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);  
	ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS ;  
	ShExecInfo.hwnd = NULL;  
	ShExecInfo.lpVerb = NULL;  
	ShExecInfo.lpFile = csExe; 
	ShExecInfo.lpParameters = csParam;   
	ShExecInfo.lpDirectory = NULL;  
	ShExecInfo.nShow = nShow;  
	ShExecInfo.hInstApp = NULL;   
	BOOL ret = ShellExecuteEx(&ShExecInfo);  
	WaitForSingleObject(ShExecInfo.hProcess, INFINITE);  
	DWORD dwCode=0;  
	GetExitCodeProcess(ShExecInfo.hProcess, &dwCode);  
	CloseHandle(ShExecInfo.hProcess);  
	return dwCode;  
  

另外ShellExecuteEx执行cmd命令的时候, 命令行参数要加入/c 来让命令行执行完成后关闭自身。否则命令行进程会一直存在, WaitForSingleObject会一直等待。

比如: ShellRun(L"cmd.exe", L"/c sc start UlogReport",SW_HIDE); 启动一个服务。

文章来源:

https://blog.csdn.net/believe_s/article/details/82389795

以上是关于salt控制windows 窗口不显示的主要内容,如果未能解决你的问题,请参考以下文章

控制台程序不显示dos窗口的方法

windows中,要改变屏幕保护程序的设置,首先双击控制面板窗口中的(),

Windows 8 控制台任务命令窗口

导航控制器不推送新窗口

window8底部任务栏不显示怎么办

js弹出窗口的命令